1

I have an ASP.NET MVC applications and i don't want to explicitly write the actions or the views names like this :

return RedirectToAction("Index"); or return View("Home");

what is the best practice for handling those strings?

I use Visual Studio 2010 and ASP.NET MVC2

3 Answers 3

1

There's MVCContrib and inside there are extension methods allowing you to write:

return RedirectToAction<HomeController>(x => x.About());

Another possibility is T4 templates.

Sign up to request clarification or add additional context in comments.

1 Comment

Check stackoverflow.com/questions/525986/…, if you like this solution but dont want to use MVCContrib.
1

Use T4MVC. It will allow you to kill all magic strings in your code.

Comments

0

I've created a static class like so:

public static class Routing {
  public static RouteValueDictionary Index {
    get {
      return new RouteValueDictionary {
        { "controller", "Default" },
        { "action", "Index" }
      };
    }
  }
}

so i can use it like this:

return RedirectToAction(Routing.Index);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.