I am considering building a SPA using AJAX.BeginForm, however I am facing an issue when a user has JavaScript disabled, instead of redirecting him to _Layout.cshtml + PartialView.cshtml, it redirects him to just the PartialView.cshtml..
Is there a way to include the Layout and the PartialView in it (where it would be if JavaScript was enabled)?
Thanks
Edit:
Awesome.. Thanks.. I managed to get it working but I am not sure it's the best implementation..
[HttpPost]
public ActionResult Index(Newsletter newsletter)
{
if (ModelState.IsValid)
{
db.Newsletters.Add(newsletter);
db.SaveChanges();
ViewData["message"] = "thanks for signing up to our newsletter!";
if (Request.IsAjaxRequest())
{
return PartialView( "SimpleMessage" );
}
}
return View();
}
And SimpleMessage.phtml is simply just @ViewData["message"];
whereas my View.phtml I have got a condition and checks whether ViewBag["message"] is set or not. If it's set, then it means it's a postback and doesn't show the form and shows the message instead, or else it shows the form: