【问题标题】:T4MVC and DisplayModeProvider issue with fully qulified views完全限定视图的 T4MVC 和 DisplayMode Provider 问题
【发布时间】:2016-01-26 03:44:40
【问题描述】:

我有检测用户代理并创建新显示模式的代码(即“平板电脑”和“手机”)

DisplayModeProvider.Instance.Modes.Insert(1, new DefaultDisplayMode("mobile") { ContextCondition = (context => GetDeviceType(context.GetOverriddenUserAgent()) == "mobile") });

所以当我想返回一个视图时,我只需要

return View("Index")

并且显示模式将附加“Index.tablet.cshtml”或“Index.mobile.cshtml”或没有“Index.cshtml”作为默认值。

这样做的好处是,如果用户代理是“移动”并且没有“Index.mobile.cshtml”文件,它将默认为“Index.cshtml”

这很好用,但是当使用完全限定的视图名称时,就像 t4mvc 一样,“~/Views/Home/Index.cshtml” 显示模式逻辑不添加“平板电脑”或“手机”。

有没有办法让 t4mvc 只返回“索引”而不是完全限定名称?

或者您对如何解决此问题并仍然使用 t4mvc 有其他建议?

谢谢

【问题讨论】:

    标签: t4mvc


    【解决方案1】:

    只要选择return (MVC.YourController.Views.ViewNames.YourView)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-04
      • 1970-01-01
      • 2020-07-21
      • 2011-05-08
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多