Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC2 inline code in view - mixing tags
    primarykey
    data
    text
    <p>I've run into a couple different exceptions with this block of code in one of my views:</p> <pre><code>&lt;% if (Model.Book.ReviewReference == null) {%&gt; &lt;%=Html.ActionLink("Rate / review this book", "Create", "Review", null, new { id = "reviewLink" }) %&gt; &lt;% Html.RenderPartial("CreateReview"); } else {%&gt; &lt;%= Html.ActionLink("Edit this book's rating / review","Edit", "Review", new { reviewID = Model.Book.ReviewID}, new {id = "reviewLink"}) %&gt; &lt;% Html.RenderPartial("EditReview", Model.Book.Review, new ViewDataDictionary()); } %&gt; </code></pre> <p>The first error I encountered was described here: <a href="https://stackoverflow.com/questions/650393/asp-net-mvc-renderpartial-with-null-model-gets-passed-the-wrong-type/713921#713921">link text</a></p> <p>thus the <code>Html.RenderPartial("EditReview", Model.Book.Review, new ViewDataDictionary())</code> you see towards the end there.</p> <p>Another problem I encountered is when the if condition is evaluated for a <code>ReviewReference</code> that is in fact <code>null</code>, the else statement is still being reached somehow, and the second partial view is making an unsuccessful attempt to render itself.</p> <p>Have I used these alternating inline-code tags in an incorrect manner? How does one go back and forth between <code>&lt;% %&gt;</code> and <code>&lt;%= %&gt;</code> properly?</p> <p>Thank you.</p> <p><strong>Edit:</strong></p> <p>OK, I marked an answer too soon. I just tried it with the given code from the answer, and that else block is still being evaluated, and trying to pass null objects to the partial view...darn it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload