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
Or
@{
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 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
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?
Thanks!
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With