Go to definition

Jul 17, 2013 at 1:47 PM
I've got two ASP.NET MVC projects in the same solution in Visual Studio.
In one project if I go to a T4MVC link in a view and tap the shortcut for Go To Definition Visual Studio takes me to the actual ActionResult definition.

In the other project if I do exactly the same thing it takes me to the T4MVC Generated file.
Any ideas why this might be? Both projects have the same version of T4MVC

Thanks

Chris
Coordinator
Jul 17, 2013 at 10:50 PM
Can you give examples of what the code looks like (and what specific token you're looking up)? There are lots of different ways to use T4MVC, and Go to Def can do various different things.
Jul 18, 2013 at 10:02 AM
Edited Jul 18, 2013 at 10:04 AM
I've figured it out.

It's where I had an ActionResult declared something like so:
public virtual ActionResult Index(Filter filter)
{
   //get results
  Services services  = getServices();
   if (filter!=null)
   {
      //filter results
      services=services.filter(filter)
   }
  return view(services)
}
I'd then use the t4MVC in some places like so:
@Html.ActionLink("List Services", MVC.Services.Index(), new { @class = "servicesToolbar" })
However since I didn't pass a filter object in Visual Studio assumed the t4MVC was the defintion I wanted.

To resolve this all I needed to do was make the filter an optional parameter. (The model binder doesn't care about it being optional hence I'd not bothered previously)
public virtual ActionResult Index(Filter filter=null)
{
...
}
Then rerun T4MVC - and it all works!

VS now gives me the correct definition.

Thanks David.
Coordinator
Jul 18, 2013 at 3:32 PM
Ah yes, that makes sense. Thanks for following up!