如何在mvc4中保存html表中的数据 [英] How do I save data from html table in mvc4
本文介绍了如何在mvc4中保存html表中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮帮我
kunjammu
< table id =listcellspacing =0cellpadding =0>
< tr>
< th>
@ Html.DisplayNameFor(model => model.Date)
< / th>
< th>
@ Html.DisplayNameFor(model => model.CategoryID)
< / th>
< th>
@ Html.DisplayNameFor(model => model.TimeTaken)
< / th>
< th>
@ Html.DisplayNameFor(model => model.Comments)
< / th>
< th>
< / th>
< / tr>
@for(int i = 0; i< 10; i ++)
{
< tr>
< td>
@ Html.TextBoxFor(model => model.Date,new {@id =date+ i,@ class =datepicker})
< / td>
< td>
@ Html.DropDownListFor(model => model.CategoryID,(IEnumerable< SelectListItem>)ViewData [categories],new {@id =category+ i})
< / td> ;
< td>
@ Html.TextBoxFor(model => model.TimeTaken,new {@id =time+ i,@ class =time})
< / td>
< td>
@ Html.TextBoxFor(model => model.Comments,new {@id =comments+ i})
< / td>
< / tr>
}
< / table>
解决方案
这很简单,就像你需要将FormCollection作为参数一样在你的功能。这样您就可以获得值。欲了解更多信息,请访问以下链接:
在MVC4中获取动态生成的多行控制值
i have a table like below. it have 10 rows. i want to save the data entered in this table to database. how can it possible in mvc4
please help me
kunjammu
<table id="list" cellspacing="0" cellpadding="0"> <tr> <th> @Html.DisplayNameFor(model => model.Date) </th> <th> @Html.DisplayNameFor(model => model.CategoryID) </th> <th> @Html.DisplayNameFor(model => model.TimeTaken) </th> <th> @Html.DisplayNameFor(model => model.Comments) </th> <th> </th> </tr> @for (int i = 0; i < 10; i++) { <tr> <td> @Html.TextBoxFor(model => model.Date, new { @id = "date" + i, @class = "datepicker" }) </td> <td> @Html.DropDownListFor(model => model.CategoryID, (IEnumerable<SelectListItem>)ViewData["categories"], new { @id = "category" + i }) </td> <td> @Html.TextBoxFor(model => model.TimeTaken, new { @id = "time" + i, @class = "time" }) </td> <td> @Html.TextBoxFor(model => model.Comments, new { @id = "comments" + i }) </td> </tr> } </table>
解决方案
This is simple, like you need to have FormCollection as argument in you function. This way you can get the values. For more knowledge just go to this link:
Get dynamically generated multiple row control values in MVC4
这篇关于如何在mvc4中保存html表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文