T4MVC and Resharper Navigation

2019-05-08 07:14发布

问题:

I frequently use Resharper's 'Go to Declaration' (ctrl + b in the Resharper Default Keymapping) keyboard shortcut to help with navigation within VS2010. Before I included a reference to T4MVC in my application, I would use "string refrences" and Resharper would know where I 'meant' to go.

For example:

@Html.Partial("_Continents" )

When I would use ctrl+b on the string "_Continents", Resharper knew I wanted to go to the partial view named _Continents.cshtml.

Since I have started using T4MVC, the same snippet above could be written:

@Html.Partial( MVC.CascadingDropDownLists.DropDownAjaxPost.Views._Continents )

When I use ctrl+b on _Continents, instead of taking me to the partial view, it takes me to the T4MVC generated code.

Is there any way to keep T4MVC in the project (I really like the strongly typed feel and intellisense support), while restoring the original navigation?

回答1:

Unfortunately, ReSharper's MVC navigation works only on constants. If T4MVC will generate consts instead of readonly fields - it should works.



回答2:

I created a small Visual Studio macro to help with this. It has issues, but it is far better than nothing IMO. It replaces F12, so you don't have to use a separate function for each.

I've posted it here:

Visual Studio macro to navigate to T4MVC link