ASP.NET MVC: Action Names & NonAction method (ambiguous between error the action methods) | Coding Cluster - using asp.net, c#, mvc 4, iphone, php, ios, javascript, in asp.net mvc 3 & more
 

ASP.NET MVC: Action Names & NonAction method (ambiguous between error the action methods)

Tuesday

MVC Case Sensitivity & Action Names & NonAction Attribute
                                                  In MVC URLs not being case sensitive. For example if you have the request “Home/About” this goes to HomeController and About action, as well as hOmE/AbOUT is going to the same controller and same action method.

Suppose if you have two about action methods in the same controller with different cases such as:

public class HomeController:Controller{
    public ViewResult About()    {
        return View();
   }
    public ViewResult aBOut()
    {
        return View();
    }
}

You will get "ambiguous between the action methods ".
when I call action method About using following url http://your applicationname/Index/ABOUT I got this server error



This means, The framework doesn't determine which "about" function to call, and throws the exception telling that the call is ambiguous. To fix this problem is to change the action name. If for some reason you don’t want to change the action name, and one of these function is not an action, then you can decorate this non action method with NonAction attribute. 

Example:

[NonAction]
public ActionResult aBOut()
{
   return View();
}
Please share this post with your friends. If it's useful to you. Thanks!.

1 comments:

Anonymous said...

Good, Thanks

Post a Comment

Share your thoughts here...

 
 
 

RECENT POSTS

Boost

 
Blogger Widgets