ASP.NET MVC Framework


This part of code:

<% foreach (Review r in ViewData.PreviousReviews)

{%>

<li><%=Html.RenderUserControl(“~/Views/MyContribution/PreviousReview.ascx”, r)%></li>

<%}%>

Generates multiple controls with SAME id property. It’s wrong in my opinion. So when you trying to access them from client script or server side code by getElementById() or FindControl() you will always hae access only to first one, because all other controls have the same identity!

So I need to use some additional syntax to fight this:

<% foreach (Review r in ViewData.PreviousReviews)

{%>

<li><%=Html.RenderUserControl(“~/Views/MyContribution/PreviousReview.ascx”, r, new {ID = “cr” + r.ReviewId})%></li>

<%}%>

In contrast in standard ASP.NET when we generates multiple controls (in repeater for example) without identities, they automatically receive different auto-generated id.

There are several changes in Preview 3 we need to know about, because there is a reason why your old code don’t want to compile :)

1. The “FilterExecutingContext” (using in the OnActionExecuted method) and “FilterExecutedContext” (using in the OnActionExecuting method) are now called “ActionExecutingContext”/”ActionExecudedContext”.

2. RenderView is now only available from ComponentController class, not from Controller class.

More about Using an ActionFilter.

MVC Changes Since Preview 2