ASP.NET MVC: ActionName action filter
ActionName action filter allow us to change name of action method while we are accessing it via url. By default we can access action method with {controller}/{action} pattern but in some case we don’t want action method to be accessible by its name. So in such case we can use ActionName action filter attribute.
We can pass custom action name as an argument with this attribute. We also need to create or rename existing view to custom action name passed as argument. Because once we use ActionName attribute, MVC framework will consider this custom action name as a name of action and actual method name will not be taken in consideration.
Attribute Usage: Only method
Sample Code:
[ActionName("AboutBlog")]
public ActionResult About()
{
return View();
}
Note: ActionName attribute require view with similar name to argument passed. In above case return View() will look for AboutBlog.cshtml and not for About.cshtml.
Check out ASP.NET MVC: Action filter series post to read about other available action filters.
You can follow me on twitter for latest link and update on ASP.NET & MVC.