Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a tool for compile time checking of MVC links?

Tags:

asp.net-mvc

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?

like image 532
Joshua Frank Avatar asked Oct 22 '25 14:10

Joshua Frank


1 Answers

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

like image 124
Dmitry Efimenko Avatar answered Oct 25 '25 13:10

Dmitry Efimenko