Asp.net-mvc – CS1963: An expression tree may not contain a dynamic operation

asp.net-mvcasp.net-mvc-3c#-4.0

I've seen many answers to my question below which seems to be '@model MyModel' but it doesn't help me with the code I'm using.

Background: I'm working on an MVC project with MVC3 (without Razor) on VS2010. I've written a control which I reference in a page:

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

ListGrid.ascx is not a strongly typed view. Therefore it inherits a dynamic type:

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

I understand that lamda expressions can't be used with a non strongly typed view so,

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

would display the error CS1963: An expression tree may not contain a dynamic operation.

As I mentioned the answer I've found is to include @model but what would be the equivalent to get my non strongly typed view to work if I'm not using Razor?

Not using Razor is not my choice and is not an option, so please don't ask why I'm not using it.

Best Answer

Change your declaration at the top of the page to:

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