Format ASP.Net MVC app for desktop and mobile browser

爱⌒轻易说出口 提交于 2019-12-20 10:57:07

问题


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


回答1:


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...)




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1670269/format-asp-net-mvc-app-for-desktop-and-mobile-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!