【发布时间】:2012-11-22 14:36:05
【问题描述】:
我的 mvc 网站在移动和非移动浏览器上运行良好;我遇到的问题是这个。我有几个操作(出于日志记录的原因)我不想在上面执行return RedirectToAction(...); 所以我一直在使用return View("OtherView", model); 这一直有效,直到我在移动设备上尝试它,它没有找到 OtherView.Mobile .cshtml。有没有办法让这个工作?
这是风景
Views/Account/Create.cshtml
Views/Account/Create.Mobile.cshtml
Views/Account/CreateSuccess.cshtml
Views/Account/CreateSuccess.Mobile.cshtml
这就是行动
public ActionResult Create(FormCollection form)
{
TryUpdateModel(model);
if(!ModelState.IsValid) { return View(); } // this works correctly
var model = new Account();
var results = database.CreateAccount(model);
if(results) return View("CreateSuccess", model); // trying to make this dynamic
return View(model); // this works correctly
}
通常我只会对帐户详细信息页面执行return RedirectToAction(...);,但这会生成一个额外的日志条目(对于正在读取的该用户),并且详细信息页面无权访问密码。由于ActionResult Create原来有密码,所以可以显示给用户确认,以后再也见不到了。
明确地说,我不想做if (Request.Browser.IsMobileDevice) mobile else full,因为我可能最终会为 iPad 或其他设备添加另一组移动视图:
Views/Account/Create.cshtml
Views/Account/Create.Mobile.cshtml
Views/Account/Create.iPad.cshtml
Views/Account/CreateSuccess.cshtml
Views/Account/CreateSuccess.Mobile.cshtml
Views/Account/CreateSuccess.iPad.cshtml
【问题讨论】:
标签: c# asp.net asp.net-mvc mobile views