Getting the red underline on view names when using custom methods in Visual Studio
asp.net-mvc, c#, razor, resharper, visual-studio
Solution
Apparently all you need to do is use JetBrains Annotations since this is a ReSharper feature.
public void SomeHelper(this HtmlHelper,[AspMvcController] string controller, [AspMvcAction] string Action, [AspMvcView] string viewName)
{
}
Problem
I have a lot of extension methods/helper classes for ASP MVC that take in controller names, action names, or view names as parameters(much like the default HtmlHelper methods). Visual Studio usually underlines these names with a straight red line to indicate that they match a valid controller/action/view when you use one of the built in MVC methods. Is there a way to get this same support for my own methods? It's a nice little feature, but that feature slowly disappears when I stop using built in methods. Quick example: This will have a straight red line underneath the "SomeViewName" string if that view is known to exist, otherwise the string itself becomes red colored. ``` public ActionResult SomeAction() { return View("SomeViewName"); } ``` And this would be an example of one of my own methods(which is in a separate library from MVC site project itself) ``` // Example action using method public ActionResult Show(int id) { return ViewOrNotFound("Show", id); } // Example of the method itself private ActionResult ViewOrNotFound(string viewName, int id) { var model = DoSomethingToGetModel(); if (model != null) { return new ViewResult { ViewName = viewName }; } else { return new HttpNotFoundResult(); } } ```