且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

一个ASP.NET MVC视图可以使用模型从不同的项目?

更新时间:2023-02-15 22:15:15

仔细检查你的浏览/ Web.config中有你引用的项目的命名空间:

Double-check that your Views/Web.config has the namespace of your referenced project:

<system.web>
  <pages>
    <namespaces>
      <add namespace="SolutionName.WpfApplication1.Model1Entities" />
    </namespaces>
  <pages>
</system.web>

更新:

我没有任何WPF应用程序在测试这个......我还以为你试图使用一个类库项目。这肯定会工作。是否有可能重构应用程序稍微拉出模式到自己的项目?这样,你可以编译成类库。

I don't have any WPF applications to test this on...I thought you were attempting to use a "Class Library" project. That will definitely work. Is it possible to refactor your application slightly to pull out the "Models" into their own project? That way you can compile it as a Class Library.

更新2:

奇怪,这几乎就像如果你的页面不是从System.Web.Mvc正确继承。确保您查看/ Web.config中是这样的:

Odd, it's almost as if your page is not inheriting correctly from System.Web.Mvc. Make sure your Views/Web.config looks like this:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <httpHandlers>
      <add path="*" verb="*"
          type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>
    <pages validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
      <namespaces>
        <add namespace="SolutionName.WpfApplication1.Model1Entities"/>
      </namespaces>
    </pages>

  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
    </handlers>
  </system.webServer>
</configuration>

更新3:
运行时错误看起来像它不是一个MVC项目。

UPDATE 3: The runtime error looks like it's not an MVC project.