cshtml開くと@usingで指定したパッケージが見つからないとエラーに
前からこんなだっけ?
I am adding a PagedList to my view and loosely following this Tutorial. I have installed the PagedList reference using Nuget, set up my controller as follows
public ViewResult Index(int page = 1) { List<Part> model = this.db.Parts.ToList(); const int pageSize = 20; return View(model.ToPagedList(page, pageSize)); }And written my view with the following model at the top
@model PagedList.IPagedList<RIS.Models.Part>When I run the page I get the following error
Compiler Error Message: CS0246: The type or namespace name 'PagedList' could not be found (are you missing a using directive or an assembly reference?) Source Error: Line 27: Line 28: Line 29: public class _Page_Areas_Parts_Views_Part_Index_cshtml : System.Web.Mvc.WebViewPage<PagedList.IPagedList<RIS.Models.Part>> {The PagedList dll is being properly loaded in my controller because when I take it out of my view everything works as expected. The CopyLocal property is set to 'True' and I have tried including the namespace in the Views\Web.Config in my specific Area. What else can I do to make the View see the Namespace?
asp.net mvc 3 - Namespace not found in MVC 3 Razor view - Stack Overflow
解決
~Views/web.configの system.web.webPages.razor/pages/namespaces にネームスペースを追加する
The first way is that use @using statement in .cshtml files, that imports a namespace to current file only, and the second: In the "web.config" file in "Views" directory of your project (notice it is not the main web.config in project's root), find this section:
<system.web.webPages.razor> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <!-- etc --> </namespaces> </pages> </system.web.webPages.razor>asp.net - How to import a namespace in Razor View Page? - Stack Overflow
NuGetアップデートした時に消えたのかなぁ。