Probably a stupid question, but here goes. In my view, I have the following code....
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Learner.MvcApplication.ViewModels.PagerViewModel>" %><%
for (int i = Model.StartPage; i <= Model.EndPage; i++)
{
%>
<% =Html.Label(ViewData.Model.Controller + i.ToString()) %>
<%
} %>
Do I have to close and reopen around the call to Html.Label "%><%" etc.?
I'd much rather do something like...
for (int i = Model.StartPage; i <= Model.EndPage; i++)
{
Html.Label(ViewData.Model.Controller + i.ToString());
}
...but the labels aren't being displayed.
Can you guess that I'm new to this??
Many thanks,
ETFairfax.
<%=x %>
is just a shortcut for Response.Write(x)
:
for (int i = Model.StartPage; i <= Model.EndPage; i++)
{
Response.Write(Html.Label(ViewData.Model.Controller + i.ToString()));
}
This is just a short-tag <%=
for <% Response.Write
note the difference between <%
and <%=
So you could very well write it like this:
for (int i = Model.StartPage; i <= Model.EndPage; i++)
{
Response.Write(Html.Label(ViewData.Model.Controller + i.ToString()));
}
One could argue which is nicer..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With