MVC 与一个控制器不同的视图文件夹
更新 - 改写问题
我将使用 JQuery Mobile 作为我正在构建的新 MVC 应用程序的移动端。由于 JQuery Mobile 将在客户端管理不同的设备,因此我创建的每个页面只需要一个移动视图。这将简化所需的视图数量,目前基本上可以归结为移动和桌面视图。
我想让一个控制器调用 2 个不同的视图,但需要注意的是这些视图位于不同的文件夹(移动设备和桌面)中。例如,控制器上的索引方法将调用构建视图路径方法
return View(BuildViewPath("Index"));
如果我的文件夹是这样的,它就可以工作,但我讨厌必须继续为每个控制器视图创建设备子文件夹
Views
Login
Desktop
Index.aspx
Mobile
Index.aspx
对于我的登录控制器,我希望视图是结构化的如下:
Views
Desktop
Login
Index.aspx
Mobile
Login
Index.aspx
我尝试返回“~/Views/Desktop/Login/Index”,但这不起作用。我了解命名约定 {controler}{view} 所以我可以明白为什么这是不正确的。
这是可能的还是不是一个好主意?如果不是,那么为 2 个不同的视图路径组织项目的最佳实践是什么。请记住,我正在寻找一个控制器。
谢谢, 保罗
UPDATE - Reworded question
I am going to use JQuery Mobile for the mobile side of a new MVC applciation that I am building. Since JQuery Mobile will manage the different devices on the client side I need only one mobile view for each page that I create. This will simplify the number of views required and basically boil it down to mobile and desktop views, for now.
I would like to have one controller call 2 different views, with the caveat being the views are in different folders (mobile and desktop). For example, the Index method on the controller would call a build view path method
return View(BuildViewPath("Index"));
It works if my folders are like this but I hate to have to keep creating device subfolders for each controller view
Views
Login
Desktop
Index.aspx
Mobile
Index.aspx
For my login controller I would like the views would be structured as follows:
Views
Desktop
Login
Index.aspx
Mobile
Login
Index.aspx
I tried returning "~/Views/Desktop/Login/Index" but that did not work.I understand about the naming convention {controler}{view} so I can see why this isn't right.
Is this possible or is it not a good idea? If not, what is the best practice for organizing a project for 2 different view paths. Remember, I am looking for one controller.
Thanks,
Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是解决方案 http ://www.asp.net/learn/whitepapers/add-mobile-pages-to-your-aspnet-web-forms-mvc-application
Here is the solution http://www.asp.net/learn/whitepapers/add-mobile-pages-to-your-aspnet-web-forms-mvc-application