处理 ASP.NET MVC 2 应用程序的移动版本的最佳实践方法是什么
MVC 的优点在于关注点分离,尤其是来自 Asp.net webforms 世界的关注点分离。
我现在有一个包含控制器、操作、模型和视图的 MVC 站点。
看看我的网站,我可以看到,要提供它的移动版本,我所要做的就是交换它的视图部分,并保持控制器、操作和模型不变。
但是,这种“交换”的最佳方法是什么,特别是在 Asp.net MVC 2 中?
控制器和视图之间不可避免地存在一些耦合。例如,某些操作反映视图的名称,从而按约定进行连接。有时,视图是在返回模型时显式定义的。
有时,控制器中的操作甚至包含基于是否是 jax 调用的条件,以返回不同的视图,例如部分视图。
因此,考虑到这一点,假设我对当前的网站很满意,但现在我想创建它的 iPad 版本。因此它包含用于触摸事件的特殊 js 库,并且视图可能不那么冗长,当然 CSS 也不同。
如何将其构建到我的 MVC 2 项目中?
干杯
The beauty of MVC is the separation of concerns, especially coming from the Asp.net webforms world.
I now have an MVC site with the Controllers, the actions, the model, and the views.
Looking at my site I can see that to serve a mobile version of it, all I have to do is swap out the Views section of it, and keep the Controllers, Actions, and Models untouched.
However, what is the best approach for this "swapping" out, specifically in Asp.net MVC 2?
Invetably there is some coupling between the controllers and the views. For example, certain actions reflect the names of the view, thus wiring by conventions. Sometimes the view is explicitly defined when returning the model.
Sometimes even, the actions in the controller contain conditions based on, is this an jax call, to return different views, like partial views for example.
so, with this in mind, say I'm happy with my current site, but now I want to create, say, an iPad version of it. So it my contain special js libraries for touch events, and the views may be less verbose, and of course the CSS different.
how do I build this into my MVC 2 project?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想到的一种方法是创建自己的 ViewEngine 并覆盖 FindView,它可以访问控制器上下文,从而访问 HttpContext。您可以使用它来根据用户代理选择不同的视图,使用某种模式,例如附加 _ipad 或其他内容。
简单示例:
Global.asax
CustomViewEngine:
One approach, off the top of my head, would be to create your own ViewEngine and override FindView, it has access to the controller context and therefore the HttpContext. You can use that to choose different views based on the user agent, using some kind of pattern, like appending _ipad or something.
Quick Example:
Global.asax
CustomViewEngine: