I am working on an ASP.Net MVC application that with views that I want to be able to format for desktop browsers as well as mobile browsers. Both formats would use the same Controllers and Actions but require different views.
What's the best way to do this? Do I do a browser detect in the Action and then invoke the appropriate view? Does the view do the browser detect and then render itself accordingly? Is there something in between return View();
and when the view actually is processed that I can override?
Thanks
ScottHa has this post about targeting multiple devices with ASP.NET MVC addressing that same problem.
I would suggest either in the view or in something between the controller and the view (the ViewEngine...)
I'd go with custom attributes stuffing appropriate views/masterpages around the returned Model. We use this tactic heavily for Ajaxification, shouldn't be difficult to extend the concept to mobile.
I would detect the browser in the controller and return the appropriate view. I guess you could override the view engine but that really seems like overkill to the extreme.