MVC3 Razor - @Html.Partial getting called but if it renders is based upon locationhttp://forums.asp.net/t/1801599.aspx/1?MVC3+Razor+Html+Partial+getting+called+but+if+it+renders+is+based+upon+locationThu, 10 May 2012 12:43:14 -040018015994971568http://forums.asp.net/p/1801599/4971568.aspx/1?MVC3+Razor+Html+Partial+getting+called+but+if+it+renders+is+based+upon+locationMVC3 Razor - @Html.Partial getting called but if it renders is based upon location <p>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.</p> <p>Here is the partial:</p> <pre class="prettyprint">@using WebUI.Domain.Digital @if (null != ViewData[&quot;SelectedRow&quot;]) { CardDigital cardDigital = (CardDigital)ViewData[&quot;SelectedRow&quot;]; string location = (string)ViewData[&quot;Location&quot;]; &lt;fieldset&gt; &lt;legend&gt;Digital Card (@location)&lt;/legend&gt; &lt;div class=&quot;display-label&quot;&gt; FirstName&lt;/div&gt; &lt;div class=&quot;display-field&quot;&gt; @cardDigital.FirstName &lt;/div&gt; &lt;div class=&quot;display-label&quot;&gt; LastName&lt;/div&gt; &lt;div class=&quot;display-field&quot;&gt; @cardDigital.LastName &lt;/div&gt; &lt;/fieldset&gt; }</pre> <p>And here is the View code calling the Partial:</p> <pre class="prettyprint">&lt;div&gt; &lt;div&gt; ... @if (grid.HasSelection) { ViewData["SelectedRow"] = new CardDigital((CardDigital)grid.SelectedRow.Value); ViewData["Location"] = "A"; } @Html.Partial("Partial/_DigitalPreview"); &lt;/div&gt; &lt;/div&gt; &lt;div&gt; @{ ViewData["Location"] = "B"; } @Html.Partial("Partial/_DigitalPreview") &lt;/div&gt;</pre> <p>Notice that there are two locations &quot;A&quot; and &quot;B&quot;. Both @Html.Partial receive the same ViewData[&quot;SelectedRow&quot;], but only Location &quot;A&quot; is rendering. I validated that @Html.Partial at Location &quot;B&quot; is getting the data, but it just is not presenting it.</p> <p>What could be the issue?</p> <p>Thanks</p> <p><br> &nbsp;</p> 2012-05-08T20:46:47-04:004974700http://forums.asp.net/p/1801599/4974700.aspx/1?Re+MVC3+Razor+Html+Partial+getting+called+but+if+it+renders+is+based+upon+locationRe: MVC3 Razor - @Html.Partial getting called but if it renders is based upon location <p>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.&nbsp;</p> <p>Simple test to verify this</p> <p>In you partial view just print &quot;<span style="white-space:pre">ViewData.GetHashCode()&quot; and see if the hash code is the same when inside the partial view while render at location A and B</span></p> 2012-05-10T12:43:14-04:00