0

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

<%= Html.HiddenFor(m => m.Property) %>
kosnkov
  • 5,609
  • 13
  • 66
  • 107
  • won't work in what way? What compile/run-time time error are you having? Is there a model declared on the view where you're doing the `HiddenFor`? – von v. Apr 30 '13 at 12:11
  • there are no problem with compiliation, just there are null values – kosnkov Apr 30 '13 at 12:48
  • the following thread shows what you need to do. http://stackoverflow.com/questions/6850174/html-hiddenfor-value-property-not-getting-set – Allen Wang Apr 30 '13 at 12:50

1 Answers1

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.

 <%= 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.

EDIT:

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

RenderPartial

Hopes its help your!

Fals
  • 6,813
  • 4
  • 23
  • 43