'Find broken controller actions
How do I find broken Html.ActionLinks?
e.g. Find Html.ActionLink("View", "ViewCustomer", "Customer") where CustomerController.ViewCustomer() no longer exists.
Solution 1:[1]
If you looking for systematic approach install (can use NuGet) and apply T4MVC.
I did it to my own project - all your magic strings (not only action links, but everything that require strings) disappear across your application. You end up using only strongly typed helpers to eliminate the use of literal strings.
In your case in particular
@Html.ActionLink("View", "ViewCustomer", "Customer")
will become
@Html.ActionLink("Externalize me as well!", MVC.Customer.ViewCustomer())
and if you externalize the one suggested, it will become what you looking for:
@Html.ActionLink(Config.ViewLabel, MVC.Customer.ViewCustomer())
Isn't it a beauty? I think this supposed to be de facto standard rather than "stringified" approach.
Look to what it does to your project: In Views:
@Html.RenderPartial(MVC.Customer.Views.YourView)
In controllers:
return View(Views.YourView);
or
RedirectToAction(MVC.Home.MyAction().AddRouteValues(Request.QueryString));
Hope this helps.
Solution 2:[2]
The accepted solution does not answer the question. Here's my solution (not sure if it requires Resharper or not).
- Click on any broken action (create one if you must)
- Hover the red bulb
- Hover Inspection MVC
- Hover Find similar issues in >
- Click custom scope
- Restrict your scope (it might tell you 10000's of quality issues)
- Search "resolve action" in the results
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
