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:
Please share this post with your friends. If it's useful to you. Thanks!.
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.
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(); }
1 comments:
Good, Thanks
Post a Comment
Share your thoughts here...