I'm running into a strange issue in more than one page of my ASP.NET MVC site. When I POST a form and the Model is NOT valid, I try to return the same view so that I can see the errors - however, instead of the page getting reloaded, I get a pop-up download box that says that the file is in "application/json" format. As you can see from the code below, the controller method returns an ActionResult and NOT a JsonResult:
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
var isValid = IsUserAuthenticated(model);
if (isValid)
{
if (!String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return User.IsInRole("Administrator")
? RedirectToAction("Index", "Admin")
: RedirectToAction("Index", "Home");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
When I submit my form without filling it out, I can see that the Model fails validation (correctly), but when it reaches the last line "return View(model);" - it returns all the HTML that I expect - but the content type is set to "application/json". I don't set the content-type anywhere in my code - so I can't figure out why this happening. The same thing is happening on other pages as well, so I'm thinking that there's some fundamental thing that I'm doing wrong - but I can't seem to figure it out.
Any thoughts?