Search code examples
asp.netasp.net-mvcrazorviewdata

Passing viewdatadictionary to partial view


I have partial view call in my application:

<div id="Pozicije"> @Html.Partial("_Pozicije", Model.pozicije, null)</div> 

that works. I have changed it to:

<div id="Pozicije"> @Html.Partial("_Pozicije", Model.pozicije, new ViewDataDictionary { { "Pozicije", true } })</div>

And this is not working, because model become null and partial view won't load.

Can someone help with this?


Solution

  • I beleive this is becuase your model property name matches the view data item key value. They are both pozicije. Try another key value for view data dictionary. I used to have similar problem and fixed that by changing view data key value.

    Hope it helps!