开发者

asp.net mvc 3 'ModelType' is not declared

开发者 https://www.devze.com 2023-02-25 13:58 出处:网络
I created an Asp.NET MVC 3 web application. However, when I try to deploy it I get this error. \'ModelType\' is not decla开发者_如何学运维red. It may be inaccessible due to its protection level.

I created an Asp.NET MVC 3 web application. However, when I try to deploy it I get this error.

'ModelType' is not decla开发者_如何学运维red. It may be inaccessible due to its protection level.

on the second line of the code where I declare my model type. It works great locally where MVC 3 is installed but not on the server where it isn't. I've included all the dll's that it normally requires to run without the installation. Also this code works fine on another server where MVC 3 isn't installed so I'm not sure what the problem is.

here is the beginning of the code:

@Imports System.Data.SqlClient
@ModelType SqlDataReader

@Code
    Layout = Nothing
End Code

it fails on the second line


This would happen if the MvcWebPageRazorHost wasn't registered.

Make sure that you have the configuration in your ~/Views/Web.config on that server:

<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" />
        </namespaces>
    </pages>
</system.web.webPages.razor>


Make sure the Web.config file in the \Views\ folder still exists. I accidentally deleted mine which caused the error "@ModelType is not declared. It may be inaccessible..."

0

精彩评论

暂无评论...
验证码 换一张
取 消