开发者

insertion through loop in mvc

<% 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


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);
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜