I need to ensure that an application I am developing is accessable and also works with JavaScript turned off. I just need a pointer to assist with the following.
I had 3
You can check the IsMvcAjaxRequest property and use it inside your controller and then return a partial view (user control) or JSON result if true, or the full View if it's false.
Something like this:
public ActionResult List()
{
if (!Request.IsMvcAjaxRequest())
{
// Non AJAX requests see the entire ViewPage.
return View();
}
else
{
// AJAX requests just get a trimmed down UserControl.
return Json(...);
}
}
More info here: MVC AJAX Sites That Gracefully Degrade
(ref. your previous answer): You could pass a value in your Request.Form to signal that this is a browser with or without javascript enabled, and then create a controller factory that will instantiate the appropriated controller according to what you get in Request.Form; a default controller for regular requests (browsers with javascript enabled) and a "Fallback controller" that only returns full views instead. I am not sure if having twice the number of controllers is better than those if-else statements around a single controller, but I guess it's a question of personal preference.
I bet there are simpler solutions, though..I wish this question had more exposure.