c# - Get variables in PartialView -
say pass data partial view this
@html.partial("_landingpage_casestudieslist", new { trackaction = "case study click", casestudies = model.casestudies })
how data in partial?
i have tried model["trackaction"]
, model.trackaction
neither work , don't know else try.
if debug code can see properties don't know use them back
here partial
<ul id="case-studies-list" class="table"> @{ int counter = 1; foreach (asset casestudy in casestudies) { <li class="@(counter == 1 ? "first " : string.empty)cell"> <a href="@casestudy.url" class="track-event" data-action="@trackaction" data-label="case study download" data-value="@casestudy.name" target="_blank"> <span class="sprite @string.format("case-study{0}", counter)"></span> <span class="text"> @html.raw(casestudy.name)<br /> <span class="font11">@html.raw(casestudy.location)</span> </span> </a> </li> counter++; } } </ul>
this image of when debug: http://i.imgur.com/oirewzv.gif
you can pass anonymous object model partial view way have in question:
@html.partial("_landingpage_casestudieslist", new { trackaction = "case study click", casestudies = "fsdffd" })
then have couple of options in partial view:
do not declare model in view (i.e. not include statement
@model mymodel
@ top)declare model dynamic (i.e. include statement
@model dynamic
)
in both cases should able access properties in
@model.trackaction @model.casestudies
also, not have intellisense on view file , receive exception @ runtime if property doesn't exist in model.
Comments
Post a Comment