剃刀视图中的ASP.NET MVC 4命名空间问题 [英] ASP.NET MVC 4 namespace issue in razor view

查看:62
本文介绍了剃刀视图中的ASP.NET MVC 4命名空间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将以下名称空间添加到我的Views web.config文件中:

I've added the following namespace to my Views web.config file:

<add namespace="System.Web.Mvc.Html5" />

现在的问题是,在视图中,我只能使用使用全名的类型:

Now the issue is that in the Views, I can only use the types using the fullname:

@System.Web.Mvc.Html5.InputTypes.Html5TextBox()

我希望能够做到:

@InputTypes.Html5TextBox()

我该怎么做?

推荐答案

确保已将此名称空间添加到~/Views/web.config文件而不是标准~/web.config文件中:

Make sure you have added this namespace to the ~/Views/web.config file and not to the standard ~/web.config file:

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />

        <add namespace="System.Web.Mvc.Html5" />
      </namespaces>
    </pages>
</system.web.webPages.razor>

还要确保在添加此命名空间后,您已经关闭并重新打开Visual Studio中的Razor视图,以使更改生效.

Also make sure that after adding this namespace you have closed and reopened your Razor view in Visual Studio for the changes to have taken effect.

这篇关于剃刀视图中的ASP.NET MVC 4命名空间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆