views:

55

answers:

3

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?

A: 

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>
jpg
but ,it tell me that the "Model" didn't exits in the current context.
+2  A: 

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>
A: 

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

Jeremy
Note the equal sign
Jeremy