1
<% for (var i = 1; i <= (Int32)ViewBag.NoofPersons; i++)
   { %>
    <%:Html.DropDownList("SalutationSalutationId"+i, (SelectList)ViewBag.SalutationSalutationId, new { @style = "width:60px" })%>   
     <input type="text" class="min_width91" value="First Name" onfocus="if (this.value == 'First Name') {this.value = '';}"
                                onblur="if (this.value == '') {this.value = 'First Name';}" id="FirstName<%: i %>" name="FirstName" />

<% } %>

i created a loop using mvc 3 aspx application to get details of name and salutation. i need to insert these values through loop in table. how it is possible. In controller page how can i write codings. when value of i increments id will be incremented

1 Answer 1

2

Your question does not make all that much sense, but I will take a stab at what you are looking for.

<table>
  <% for (var i = 1; i <= (int)ViewBag.NoofPersons; i++)
     { %>
       <tr>
         <td><% i %></td>
       </tr>
  <% } %>
</table>

EDIT

<table>
  <% foreach (User user in Model)
     { %>
       <tr>
         <td><input type="text" id="textbox<% i %>" name="textbox<% i %>" value="<% user.Name %>" /></td>
       </tr>
  <% } %>
</table>

your controller query should be along these lines ...

public ViewResult Index()
{
  using (DbEntities db = new DbEntities())
  {
    return View(db.Users);
  }
}
2
  • the thing is that i need to insert name in 5 textboxes. and the id is like textbox1,textbox2,... how i write codings in controller page. ui iscorrect and i added the coding of ui Sep 16, 2011 at 12:20
  • @Aswathi you must not do any markup output in controller. Controller only checks query, access model to get data, do you business logic and pass data to view. view outputs markup and what bdparrish showed you is a part of the view that you have to use
    – vittore
    Sep 16, 2011 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.