开发者

Asp.net MVC 3 code generation fails with n-tier application

开发者 https://www.devze.com 2023-02-07 03:28 出处:网络
When I try to generate strongly typed Views based on models outside of my mvc project (in the business layer project), I get no code generation for the View. So for example my details page doesn\'t au

When I try to generate strongly typed Views based on models outside of my mvc project (in the business layer project), I get no code generation for the View. So for example my details page doesn't automatically generate the table to display the detail of the model passed to it. This is not the case when the models are directly inside of my MVC project. Is it possible to have an n-tier application and still get this code generation for strongly typed views?

EDIT: Answer-

Add a li开发者_C百科ne for your namespace of the business layer into the web.config of the views folder like so

  <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="<My business layer namespace>" />
     </namespaces>
    </pages>
  </system.web.webPages.razor> 

Then code generation will work when you create a strongly typed view.


Try custom ViewModels or importing the namespace into the page:

<%@ Import Namespace="Your.Namespace.Here" %>

It also looks like you may need to add the assembly information to the web.config that's located in your Views folder.

0

精彩评论

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