【问题标题】:CS1963: An expression tree may not contain a dynamic operationCS1963:表达式树可能不包含动态操作
【发布时间】:2013-07-27 08:10:08
【问题描述】:

我在下面看到了很多我的问题的答案,似乎是“@model MyModel”,但它对我正在使用的代码没有帮助。

背景:我正在 VS2010 上使用 MVC3(无 Razor)开发 MVC 项目。我写了一个我在页面中引用的控件:

 <% Html.RenderPartial("~/Views/ListGrid.ascx", new UpdateRequest { Id =Int32.Parse(ViewData["Id"].ToString())}); %> 

ListGrid.ascx 不是强类型视图。因此它继承了一个动态类型:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>"  %>

我知道 lamda 表达式不能用于非强类型视图,所以,

<%=Html.TextBoxFor(l => Model.ExpiryYear)%>

将显示错误 CS1963:表达式树可能不包含动态操作。

正如我所提到的,我找到的答案是包含 @model,但是如果我不使用 Razor,那么让我的非强类型视图工作的等价物是什么?

不使用 Razor 不是我的选择,也不是一个选项,所以请不要问我为什么不使用它。

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-3 c#-4.0


    【解决方案1】:

    将页面顶部的声明更改为:

    <%@ Control Inherits="System.Web.Mvc.ViewPage<IEnumerable<YourModel>>" %>
    

    【讨论】:

      猜你喜欢
      • 2014-07-14
      • 1970-01-01
      • 2012-05-13
      • 1970-01-01
      • 2011-10-30
      • 2012-05-05
      • 1970-01-01
      • 2012-09-07
      相关资源
      最近更新 更多