MVC lambda不适用于RenderPartial

时间:2022-01-11 03:24:58

on one page i am rendering other view this way:

在一个页面上我以这种方式渲染其他视图:

<% Html.RenderPartial("Angebotspruefung", new ViewDataDictionary {{ "OpportunityEditModel", Model }} }); %>

and on rendered view I retrive this model this way:

在渲染视图中,我以这种方式检索此模型:

<% 
    OpportunityDetailsEditModel model = (OpportunityDetailsEditModel)ViewData["OpportunityEditModel"];    
%>

and there is sth very very wird, i can acces properties with <%= model.Property %> but lambda does't work , so this won't work

非常非常奇怪,我可以使用<%= model.Property%>访问属性,但lambda不起作用,所以这不起作用

<%= Html.HiddenFor(m => m.Property) %>

1 个解决方案

#1


1  

Lamda expression Helpers works only with strongly typed views. Intead of passing ViewData, make your Partial View Strongly typed and pass to Html.RenderPartial the Object Model. Then, you will have the expected functionality with lambda.

Lamda表达式Helpers仅适用于强类型视图。传递ViewData的Intead,使您的部分视图强类型化并传递给Html.RenderPartial对象模型。然后,您将获得lambda的预期功能。

 <%= Html.HiddenFor(m => m.Property) %>

In this code above m is suposed to be the model from its view, so the helper tries to render the control, but its view has no Model, its setted manually by an object, then the reflection from control render fails.

在上面的代码中,m被视为其视图中的模型,因此帮助程序尝试呈现控件,但其视图没有Model,由对象手动设置,然后控件渲染的反射失败。

EDIT:

编辑:

RenderPartial has an overload that gives you the ability of pass the model as parameter, take a look here:

RenderPartial有一个重载,使您能够将模型作为参数传递,请看这里:

RenderPartial

的RenderPartial

Hopes its help your!

希望对你有所帮助!

#1


1  

Lamda expression Helpers works only with strongly typed views. Intead of passing ViewData, make your Partial View Strongly typed and pass to Html.RenderPartial the Object Model. Then, you will have the expected functionality with lambda.

Lamda表达式Helpers仅适用于强类型视图。传递ViewData的Intead,使您的部分视图强类型化并传递给Html.RenderPartial对象模型。然后,您将获得lambda的预期功能。

 <%= Html.HiddenFor(m => m.Property) %>

In this code above m is suposed to be the model from its view, so the helper tries to render the control, but its view has no Model, its setted manually by an object, then the reflection from control render fails.

在上面的代码中,m被视为其视图中的模型,因此帮助程序尝试呈现控件,但其视图没有Model,由对象手动设置,然后控件渲染的反射失败。

EDIT:

编辑:

RenderPartial has an overload that gives you the ability of pass the model as parameter, take a look here:

RenderPartial有一个重载,使您能够将模型作为参数传递,请看这里:

RenderPartial

的RenderPartial

Hopes its help your!

希望对你有所帮助!