Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC

 

You probably are aware by now that as of ReSharper 5 we added first-class support for ASP.NET MVC. This included among many things, the ability to provide Intellisense, Create from usage and Navigation to built-in methods such as Controller.View or Html.ActionLink:

 

Navigation

Ctrl+Left Mouse Click or F12 will navigate to the corresponding View

 

image 

 

or to the Action and/or Controller

 

image

Intellisense and Create From Usage

Ability to have Intellisense when providing Actions/Controllers

 

image

 

as well as the possibility of creating from usage

image

 

However, what happens when you want to use a custom function, for instance, a better ActionLink or your own View method? Did you know that you can still get all these goodies? All you need to do is use some Annotations.

Using JetBrains.Annotations

ReSharper uses annotations via the form of .NET attributes to figure out what an ASP.NET MVC View, Action or Controller is. As such, all we need to do for our custom method and extensions to leverage this, is tell ReSharper what parameter corresponds to what.

 

Referencing the annotations

To use ReSharper annotations, we have mainly two options (with a third one hopefully coming soon):

1. We can include the library JetBrains.Annotations.dll in our project and reference it.

2. We can copy the annotations and include it as source in our project

[3. We can use nuget install-package JetBrains.Annotations] Coming soon!

 

The first option is pretty simple. The DLL is located in the ReSharper installation bin folder. For the second option, we open up ReSharper | Options and select Code Annotations entry

 

image

 

select the Copy default implementation to clipboard button and paste into an empty file.

 

Annotating custom methods

Once we’ve completed this step, all we need to do is annotate our parameters with the correct attributes. We’re interested in 3 different attributes in particular:

 

  • AspMvcView which indicates the parameter is a View
  • AspMvcAction which indicates the parameter is an Action
  • AspMvcController which indicates the parameter is a Controller

 

Here is the header corresponding to a base controller with a custom method named ExtendedView

 

image

 

and here’s the header for a custom ActionLink

image 

 

(the body of both methods are omitted and are not necessary to demonstrate the functionality)

 

As soon as we do this, ReSharper picks up these methods and offers us the same functionality that is provided for the methods that ship out of the box:

 

image

 

Notice how we still get Navigation (the underlining), Intellisense and Create from usage in our TheOnlyActionLink custom method. Its much the same for the ExtendedView method

 

image

 

That’s all there is to it.


Posted 12-07-2011 2:47 PM by Hadi Hariri
Filed under: , ,

[Advertisement]

Comments

Samee wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 11-01-2012 2:39 AM

Hi,I was able to revert back to using Visual Studio’s Intellisense, but I do not have the wnanirg of error in the view (for example: calling a method that receives an int and I'm passing a string). Is very annoying to only be able to discover the errors during debug.  Could you please tell me a way to reactivate the  error wnanirg  ? Thank you.

seo social bookmarking wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 01-17-2013 8:03 AM

IQ9L0L Say, you got a nice article. Really Cool.

Dmitry Pavlov wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 01-31-2013 9:17 AM

Right thing. Thanks! Posted the feedback to add this into stardard asp.net mvc libraries - aspnet.uservoice.com/.../3608061

Feel free to vote! ;)

lose weight pills wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 01-31-2013 9:45 AM

QE13MI Thanks for the blog. Awesome.

pills for lose weight wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 02-01-2013 11:32 PM

70THxg Thanks for the article.Thanks Again. Really Great.

buy viagra online wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 02-03-2013 3:13 PM

hDECML This is one awesome post. Awesome.

buy stendra generic wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 02-14-2013 7:49 AM

mVowZg I appreciate you sharing this article.Much thanks again. Want more.

buy stendra generic wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 02-15-2013 9:21 AM

ad3pZ6 Thanks so much for the article.Much thanks again. Fantastic.

http://clomidnoprescription.beep.com/ wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 02-28-2013 2:11 AM

6fisWy wow, awesome blog article.Much thanks again. Great.

Clomiphene 50 mg wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 02-28-2013 5:02 AM

uUWHu4 Thanks for the blog article.Really thank you! Awesome.

bookmarks wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 03-13-2013 5:35 PM

ovgzY9 Thanks for sharing, this is a fantastic article.Thanks Again. Great.

social bookmarks wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 03-14-2013 9:40 AM

yNovuV Major thanks for the blog.Thanks Again. Great.

social bookmarking service wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 03-23-2013 9:56 PM

HHSsTj Major thanks for the blog article.Much thanks again. Want more.

Social bookmarks wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 03-24-2013 9:45 PM

MFbS17 Im thankful for the article. Great.

bears wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 04-06-2013 9:16 AM

Thanks for the article post. Will read on...

comedy wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 04-06-2013 6:25 PM

Really enjoyed this blog article.Thanks Again. Keep writing.

Social bookmarks wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 04-14-2013 12:56 AM

nnJ0vh I loved your article.Really thank you! Awesome.

Social bookmarks wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 04-19-2013 12:46 PM

WTIZ8f Wow, great blog article.Really thank you! Awesome.

buy social bookmarks wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 04-24-2013 2:07 AM

VzdG4m Say, you got a nice blog post. Keep writing.

cheap social bookmarks wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 06-19-2013 7:25 AM

fVTyvI Very good post.Much thanks again. Will read on...

great service wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 07-04-2013 12:39 PM

xUkqpJ Say, you got a nice blog.Thanks Again. Great.

buy viagra online cheap wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 07-24-2013 5:49 AM

Im obliged for the blog.Thanks Again. Fantastic.

best news on earth wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 07-26-2013 8:34 AM

tDnvJ5 Thank you ever so for you article post.Much thanks again. Cool.

news wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 08-02-2013 11:19 AM

tIvZom Thanks again for the post.Really thank you! Great.

best news of them all wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 08-05-2013 1:56 AM

waAOCE This is one awesome blog post.Really looking forward to read more. Really Cool.

great link buildng wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 08-19-2013 11:40 AM

onysim Looking forward to reading more. Great post.Thanks Again. Really Cool.

great link buildng wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 08-19-2013 11:14 PM

FbU9cR Awesome blog. Awesome.

great seo service wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 09-04-2013 1:43 AM

tGRJae A big thank you for your blog.Much thanks again. Much obliged.

best place for make money online wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 09-11-2013 6:15 PM

CwLFZv I appreciate you sharing this article post.Thanks Again. Want more.

cheap link building wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 09-24-2013 6:47 AM

D7xO32 I cannot thank you enough for the blog. Great.

awesome linkbuilding site wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 10-01-2013 8:23 AM

hle0WT I really like and appreciate your article.Thanks Again. Really Cool.

link building team wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 10-15-2013 10:24 AM

y3bU66 wow, awesome blog article.Really thank you! Will read on...

link building wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 10-25-2013 8:30 PM

XXF2ur Thanks again for the article post.Really looking forward to read more. Really Great.

link building wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 11-01-2013 1:44 AM

ntJwWg I cannot thank you enough for the article post.Thanks Again. Want more.

cheap backlinks wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 07-19-2014 3:11 AM

HMQK49 Im obliged for the blog article. Keep writing.

matt wrote re: Providing Intellisense, Navigation and more for Custom Helpers in ASP.NET MVC
on 07-20-2014 2:49 AM

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)