问题描述
我学习ASP.NET MVC剃刀。
我注意到,有时一些CSHTML文件已经有一些进口的命名空间(例如,对于NopCommerce,我现在用的学习)
I am learning ASP.NET MVC with Razor.I noticed that sometimes some cshtml files already have some namespaces imported (example for NopCommerce, which I am using to learn)
@model ProductListModel
@using Telerik.Web.Mvc.UI
或者
@{
Layout = "~/Views/Shared/_ColumnsOne.cshtml";
Html.AppendScriptParts(@Url.Content("~/Scripts/jquery.fileupload.js"));
Html.AppendScriptParts(@Url.Content("~/Scripts/jquery.lightbox-0.5.min.js"));
Html.AppendCssFileParts(@Url.Content("~/Content/Style/jquery.fileupload-ui.css"));
Html.AppendCssFileParts(@Url.Content("~/Content/Style/jquery.lightbox-0.5.css"));
}
(Html.AppendScriptsParts在nop.Web.Framework.UI声明)
如果让我自己CSHTML文件,我需要添加使用行或引用的是这样的:
(Html.AppendScriptsParts is declared in the nop.Web.Framework.UI)If I make my own cshtml file, I need to add the "using" line or reference with the like this:
@using System.Linq;
@using Nop.Web.Framework.UI
@model Nop.Admin.Models.Proposal.ProposalListModel
有没有我缺少引用这些项目的任何把戏?为什么是第2实施例更简单,并且不需要显式引用?
Is there any trick I am missing to reference these items? Why are the first 2 examples simpler and do not need the explicit reference?
谢谢!
推荐答案
添加您的命名空间在这里 ... \\浏览\\ Web.config文件
:
Add your namespace here ...\Views\Web.config
:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.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.Routing" />
<add namespace="Your.Namespace" />
</namespaces>
</pages>
</system.web.webPages.razor>
这篇关于我该如何避免增加@using我CSHTML标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!