@Blog.Author(Nandip Makwana) .LearningExperience(ASP.NET, ASP.NET MVC, IIS, jQuery & Technology Surrounding it...)

October 24, 2012 comment

ASP.NET MVC: ActionName action filter

ASP.NET MVC: ActionName

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.

comments powered by Disqus

Featured Content

Resources & Tools

About Nandip Makwana

Nandip Makwana is passionate about digital world and web. He completed his Masters in Computer Application in June 2011. Currently he is working as a Software Engineer. He has shown great promise and command over ASP.NET and technologies surrounding it during his academic years and professorial life...continue reading