为什么我无法在强类型页面中调用Model和ViewData以及Html?

发布于 2024-08-10 12:25:57 字数 401 浏览 2 评论 0原文

我创建了一个新的强类型视图,如下所示:

<%@ 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>

但是当我调用模式,Html,Viewdata时,没有智能感知提示。我不明白,请告诉我该怎么做?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情绪操控生活 2024-08-17 12:25:57

我已经想到了。如果您创建强类型视图,则应该将此配置添加到视图路径下的 web.config 中:

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

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> 
青朷 2024-08-17 12:25:57

请参阅这篇有关 ViewModels 的文章。

您需要在 asp:content 中进行一些替代编码,而不是仅仅调用 <% model %> 并希望智能感知能够工作 - 您已经告诉过页面上的“模型”是什么,因此您需要做的就是开始“使用”页面上的模型。

在此示例中,来自 Stephens 的文章,迭代模型中的每个项目并构建一个列表。

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

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> 
浅唱ヾ落雨殇 2024-08-17 12:25:57

尝试使用 <%= Model.blah %>而不是 <% Model.blah %>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文