4

I've inherited a kludgy and buggy MVC code base from another developer, and I'm trying to clean it up. One thing that would be very helpful would be a tool to check, at compile time, for links that don't correspond to action methods in a controller.

For instance, you can write an action method like this:

public ActionResult InsertAccount(string Name)

and there could be a link somewhere that looks like this:

/SomeController/InsertAccount?Id=Foo

Somewhere along the way, the parameter got changed from "Id" to "Name", and this breaks the link. If everything were in C#, the compiler would catch it, but because the link is generated from strings, a change like this can't be detected.

Is there any tool that would do this, or guidelines for link construction to preserve name safety, so I can use the compiler to catch this kind of problem?

Joshua Frank
  • 13,120
  • 11
  • 46
  • 95

2 Answers2

6

Check out T4MVC

With it you can write this:

@Html.ActionLink("Insert Account", MVC.SomeController.InsertAccount("Foo"))

You still will not get a compilation error when you build since Views are not compiled by default. however, you can change this in the project file as shown here

Community
  • 1
  • 1
Dmitry Efimenko
  • 10,973
  • 7
  • 62
  • 79
3

JetBrain's resharper offers this type of checking. It offers quite a bit of help when dealing with the links between views and controllers, it shows you when you try to return a non-existing view and in the view it detects non-existing actions

Kenneth
  • 28,294
  • 6
  • 61
  • 84