"현재 모델에는 '모델'이라는 이름이 없습니다."
MVC 4 응용 프로그램에서 중요한 리팩터링을 한 후 Razor는 뷰를 디버깅하는 동안이 오류를 표시합니다.
현재 컨텍스트에 'model'이라는 이름이 없습니다.
이것은 잘못된 코드 행입니다.
@model ICollection<DataSourceByActive>
사용법 @model
이 올바른 것을 알고 있습니다.
왜 이런 일이 발생합니까? 어떻게 고칠 수 있습니까?
Views 폴더에있는 web.config 파일을 엉망으로 생각합니다.
동일한 .NET 프레임 워크를 대상으로하는 새 프로젝트를 작성하고 Views / web.config 파일을 현재 프로젝트의 파일 위에 복사하십시오. 문제가 해결됩니다.
또한 Dudeman3000이 언급했듯이 MVC 프로젝트에 영역이 있으면 모두 Views\web.config
파일이 있습니다.
확인 당신에게 두 사이트에 다음이 Web.config
및 뷰 디렉토리 Web.config
에 appSettings
섹션
<add key="webpages:Version" value="2.0.0.0" />
MVC5의 경우 :
<add key="webpages:Version" value="3.0.0.0" />
(그리고 그것은 주 Web.config
파일 에만 존재 합니다.)
여기 내가 한 일이 있습니다.
- Visual Studio 닫기
- SUO 파일 삭제
- Visual Studio를 다시 시작하십시오.
.suo 파일은 .svn 솔루션 파일과 동일한 폴더에 숨겨진 파일이며 Visual Studio 사용자 옵션을 포함합니다.
나는 같은 문제가 있었고, 새로운 프로젝트를 만들고 Gupta의 답변에서 권장하는 것처럼 web.config 파일을 복사했지만 문제가 해결되지 않았습니다. Alex와 Liam의 답변을 확인 했는데이 줄은 새 web.config에서 복사해야한다고 생각했지만 새 프로젝트 자체에는이 줄 (MVC5)이없는 것처럼 보입니다.
<add key="webpages:Version" value="3.0.0.0" />
views / web.config 파일에 줄을 추가하면 문제가 해결되었습니다.
보기 폴더의 web.config에서 다음 줄을 변경하면 동일한 오류가 해결되었습니다.
에서
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
에
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
필자의 경우 최근에 MVC 4에서 MVC 5로 업데이트되어 web.config가 상당히 나빠졌습니다. 이 기사는 엄청나게 도움이되었습니다.
결론은 web.config 및 Views / web.config에서 모든 버전 번호 참조가 MVC 5와 관련된 올바른 업그레이드 버전을 참조하는지 확인해야한다는 것입니다.
해결책을 찾았습니다. 면도기 버전 또는 mvc 4를 5로 업데이트하려면 일부 줄을 변경하십시오.
Views / web.config의 이전 코드
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
로 교체
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
sectionGroup
또한 변화해야합니다.
@model에서 @Model로 변경하면 나를 위해 일했습니다.
@model은 뷰 모델 객체 유형을 나타냅니다. @Model은 뷰 모델 객체를 나타냅니다.
필자의 경우 다음 코드가 유용하다는 것을 알았습니다. 코드 아래에 Views 폴더 아래의 Web.config 파일에 배치하십시오.
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
코드가 업데이트되면 솔루션을 정리하고 다시 작성하십시오. 나는 이것이 당신을 도울 수 있기를 바랍니다!
기존의 답변 중 아무도 나를 위해 일하지,하지만 난 무엇을 발견 했다 비교가 나를 위해 일을 .csproj
다른 프로젝트의 파일을. .csproj
XML 파일 을 다음과 같이 수동으로 편집 하면 Razor-intellisense 문제가 해결되었습니다. 아마도 다른 모든 답변을 시도하지 않은 사람이 도움이되지 않을 수도 있습니다. 핵심은 <Private>False</Private>
에서의 인스턴스를 제거하는 것입니다 <Reference>
.
<ItemGroup>
<Reference Include="Foo">
<HintPath>path\to\Foo</HintPath>
<!-- <Private>False</Private> -->
</Reference>
<Reference Include="Bar">
<HintPath>path\to\Bar</HintPath>
<!-- <Private>True</Private> -->
</Reference>
</ItemGroup>
나는 그들이 어떻게 거기에 도착했는지 또는 그들이 무엇을하는지 모르겠다. 아마도 나보다 똑똑한 사람이 그 정보를 추가 할 수있을 것이다. 마침내이 문제를 해결하게되어 기뻤습니다.
For some reason my web.config had 0.0.0.0 in the oldVersion attribute:
<runtime>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</runtime>
changing to 1.0.0.0 was the solution:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
</dependentAssembly>
For me, the issue was a conflicting .NET version in one of the libraries that I recently imported. The library I imported was compiled for 4.5.2 and the ASP.NET MVC site I imported it into targeted 4.5. After recompiling said lib for 4.5 the website would comppile.
Also, there were no compilation errors, but the issue was being reported as a "warning". So be sure to read all warnings if there are any.
In my case, the issue was that after upgrading the project from MVC 4 to MVC 5 I somehow missed a version change in the Views/web.config:
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
It still had the old 2.0.0.0 version. After changing the version to 3.0.0.0 everything started working just right.
Also, because of this problem, Visual Studio 2015 Community Edition would start bashing the CPU (30-40% usage at idle) every time I would open a .cshtml file.
I had the same problem when deploying to an Azure App Service
In my case it was because ~/Views/Web.config wasn't included in the project.
It worked in IIS Express but when I deployed to azure, I got the same error. By not being included in the .csproj file, it wasn't deployed.
The solution was to ensure ~/Views/Web.config is included in the project.
If you go to solution explorer and click the "Show all files" icon, then open up Views you might see an unincluded Web.config file under there.
Add it in, re-publish, and bob's your uncle.
I was trying to add a view which were outside of my "Views" folder (just to organize my code differently, I guess), when I had this issue. Creating the view inside Views (as by convention) solved it.
In my case I was missing @ at the beginning of the foreach
@foreach (var item in Model)
{
<tr class="clickable-row">
<td class="clickable-field">
@Html.DisplayFor(modelItem => item.Label)
</td>
<td class="clickable-field hidden-xs">
@Html.DisplayFor(modelItem => item.Value)
</td>
</tr>
}
In order to solve this I made sure that I upgraded to the newest MVC version using NuGet and Package Manager Console.
Install-Package Microsoft.AspNet.Mvc -Version 5.2.4
Then upgraded to the latest Razor version
Install-Package Microsoft.AspNet.Razor -Version 3.2.4
Then I changed all the web.config files to reflect the change. As you will see below:
In the main web.config file, make sure that the webpages:version is correct. This is where it can be found (ignore the other keys):
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
</configuration>
Then look for the other versions listed in the assemblies, check the version of the assembly against the version of the library listed in your project references! You may not need all of these.
<system.web>
<compilation debug="true" targetFramework="4.6">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
</system.web>
Runtime assemblyBinding should show the "newversion" as well, see where it reads NewVersion 5.2.4.0? But also check all the other versions.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.2.4.0" newVersion="5.2.4.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
THEN in the Views Web.Config section, make sure that Razor is the correct version:
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<configuration>
And Lastlt there is the Pages section of the Views Web.Config
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
if you take this problem without any change on your project as like as me, you need change your web.config that placed in View Folder. just write new line by Enter or Remove an empty line . then save your web.config and rebuild. my problem solved with this solution
In my case, I removed web.config file from Views folder by accident. I added it back , and it was OK.
I solved the problem by using @Model
instead of just model
when printing the variables.
You are likely to use in the code a variable named model
.
'Programing' 카테고리의 다른 글
스위프트-절대 값으로 변환 (0) | 2020.05.20 |
---|---|
Makefile의 현재 상대 디렉토리를 얻는 방법? (0) | 2020.05.20 |
grep에서 이진 파일 일치 결과를 억제하는 방법 (0) | 2020.05.19 |
GitHub 리포지토리의 포크 종속성 삭제 (0) | 2020.05.19 |
C # 자동 속성 초기화 (0) | 2020.05.19 |