Today I found it hard to discover the difference between two MVC action methods.
My arearegistration:
public override void RegisterArea(AreaRegistrationContext context)
{
// My test route.
context.MapRoute(
"testRoute",
"Test/{action}",
new { controller = "Test", action = "Index" }
);
}
And the two methods, that differ from both the used http-method and the parameter.
[HttpPost]
public ActionResult Test(TestModel model)
{
return View("Confirm", model);
}
[HttpGet]
public ActionResult Test(string title)
{
Response.Write(title);
Response.End();
return null;
}
Unregarded the http method, it will always end up rendering the second Test() method. Even when no title parameter is supplied (normally by querystring /Test/Test/?title=test). Probably because string is a reference type and can be null.
But how to overcome this problem? How to make a difference between these methods?
Thanks in advance.
I follow this signature, basically always use the ‘GET’ method signature with the model as last parameter.
By the way, I’ve never seen the behavior you’ve mentioned. So I doubt whether this is a MVC problem rather than something in your configuration. [HttpGet] methods never fire on a POST method. Is the method really post (check the Request property of your ControllerContext).