Why i can't call the Model and ViewData, and Html in the strong typed page?

156 Views Asked by At

I created a new strong typed View ,something like this:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
  Inherits="System.Web.Mvc.ViewPage<MiniMain.ViewModel.ArticleViewdata>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%Model %>
</asp:Content>

but when I called the Mode ,Html,Viewdata,then had no intellisense tips.I can't figure it,please tell me how to do this?

3

There are 3 best solutions below

0
On BEST ANSWER

I have figured it.If you create a strong typed view,you should add this config to the web.config under the View path:

<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>
</pages> 
1
On

See this article on ViewModels.

You need to do some alternative coding in the asp:content instead of just calling <% model %> and hoping that intellisense will work - you have told the page what the "model" is so all you need to do is start to "use" the model on the page.

In this example, from Stephens article, iterate of each item in the model and build a list.

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">  
    <% foreach (var item in Model)    
       { %>  
        <li> <%= item.Name %> </li>  
    <% } %>  
</asp:Content> 
0
On

Try using <%= Model.blah %> instead of <% Model.blah %>