Is it just me or has anyone else been annoyed by the fact that we have to use a lot of constants to handle redirections from one action to another across different controllers. I have tried to implement a reflection based approch to tackle this issue, but was wondering how others have approached this ( If you have seen this as an issue , of course 🙂 )
As an example, what I did is implemented something like this to get an action name.
public static string ActionName(Func<ActionResult> methodContainer)
{
return methodContainer.Method.Name;
}
and to get the controller name,
public static string ControllerName<T>() where T : class
{
Type t = typeof (T);
return t.Name.Replace(ControllerConstants.Controller, string.Empty);
}
Any better approaches than this?
/Bumble Bee
Check out MVCContrib library, link below addresses exactly the issue you’re dealing with…it’s been around since MVC v1.
http://mvccontrib.codeplex.com/wikipage?title=RedirectToAction&referringTitle=Documentation
It’s also on nuget, so it should be easy to give it a spin.
http://nuget.org/List/Packages/MvcContrib.Mvc3-ci