Notice that there are two locations "A" and "B". Both @Html.Partial receive the same ViewData["SelectedRow"], but only Location "A" is rendering. I validated that @Html.Partial at Location "B" is getting the data, but it just is not presenting it.
What i am thinking is ViewData might be different in the second time you call the partial view. First time you create a view data object and pass it to the partial view and try passing the same view data to the partial view, it is getting lost.
Simple test to verify this
In you partial view just print "ViewData.GetHashCode()" and see if the hash code is the same when inside the partial view while render at location A and B
Cheers,
Gopakumar
| Please click “Mark as Answer” on the post(s) if it helps |
jeff00seattl...
Member
44 Points
112 Posts
MVC3 Razor - @Html.Partial getting called but if it renders is based upon location
May 08, 2012 08:46 PM|LINK
I have a Partial that I know that it is getting called and validated that it is receiving expected ViewData, but it does not always render.
Here is the partial:
@using WebUI.Domain.Digital @if (null != ViewData["SelectedRow"]) { CardDigital cardDigital = (CardDigital)ViewData["SelectedRow"]; string location = (string)ViewData["Location"]; <fieldset> <legend>Digital Card (@location)</legend> <div class="display-label"> FirstName</div> <div class="display-field"> @cardDigital.FirstName </div> <div class="display-label"> LastName</div> <div class="display-field"> @cardDigital.LastName </div> </fieldset> }And here is the View code calling the Partial:
<div> <div> ... @if (grid.HasSelection) { ViewData["SelectedRow"] = new CardDigital((CardDigital)grid.SelectedRow.Value); ViewData["Location"] = "A"; } @Html.Partial("Partial/_DigitalPreview"); </div> </div> <div> @{ ViewData["Location"] = "B"; } @Html.Partial("Partial/_DigitalPreview") </div>Notice that there are two locations "A" and "B". Both @Html.Partial receive the same ViewData["SelectedRow"], but only Location "A" is rendering. I validated that @Html.Partial at Location "B" is getting the data, but it just is not presenting it.
What could be the issue?
Thanks
Jeff in Seattle
gopakumar.r
Participant
959 Points
193 Posts
Re: MVC3 Razor - @Html.Partial getting called but if it renders is based upon location
May 10, 2012 12:43 PM|LINK
What i am thinking is ViewData might be different in the second time you call the partial view. First time you create a view data object and pass it to the partial view and try passing the same view data to the partial view, it is getting lost.
Simple test to verify this
In you partial view just print "ViewData.GetHashCode()" and see if the hash code is the same when inside the partial view while render at location A and B
Gopakumar
| Please click “Mark as Answer” on the post(s) if it helps |