I've run into a couple different exceptions with this block of code in one of my views:
<% if (Model.Book.ReviewReference == null)
{%>
<%=Html.ActionLink("Rate / review this book", "Create", "Review", null, new { id = "reviewLink" }) %>
<% Html.RenderPartial("CreateReview");
}
else
{%>
<%= Html.ActionLink("Edit this book's rating / review","Edit", "Review", new { reviewID = Model.Book.ReviewID}, new {id = "reviewLink"}) %>
<% Html.RenderPartial("EditReview", Model.Book.Review, new ViewDataDictionary());
} %>
The first error I encountered was described here: link text
thus the Html.RenderPartial("EditReview", Model.Book.Review, new ViewDataDictionary())
you see towards the end there.
Another problem I encountered is when the if condition is evaluated for a ReviewReference
that is in fact null
, the else statement is still being reached somehow, and the second partial view is making an unsuccessful attempt to render itself.
Have I used these alternating inline-code tags in an incorrect manner? How does one go back and forth between <% %>
and <%= %>
properly?
Thank you.
Edit:
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.