将表值从视图传递到控制器MVC [英] Pass Table Value from View to Controller MVC
本文介绍了将表值从视图传递到控制器MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以将表td值传递给控制器吗?
Can I pass table td values to controller?
强类型查看:
@using (Html.BeginForm("PostClick", "Vendor", FormMethod.Post)) {
<table class="tblData">
<tr>
<th>
@Html.DisplayNameFor(model => model.First().SubmittedDate)
</th>
<th>
@Html.DisplayNameFor(model => model.First().StartDate)
</th>
</tr>
<tr>
<td>
@Html.DisplayFor(modelItem => item.SubmittedDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.StartDate)
</td>
</tr>
</table>
<input type="submit" value="submit" />
}
Contoller代码:
Contoller code:
public void PostClick(FormCollection collection)
{
/*Some Code */
}
如何将表值从视图传递到控制器?
How to pass table value from view to controller?
已使用JasonData&Ajax调用并能够将表数据发送到控制器.
Have used JasonData & Ajax call and able to send the table data to controller.
想知道可以使用任何其他方法,因为 FormCollection
数据无法找到表值
Want to know any other method can be done because FormCollection
data not able to find table values
推荐答案
您需要生成可回发( input
, textarea
或 select 代码>)并在
for
循环中生成这些控件(或使用自定义的 EditorTemplate
用于类型 Vendor
)
Your need to generate controls that post back (input
, textarea
or select
) and generate those controls in a for
loop (or use a custom EditorTemplate
for type Vendor
)
查看
@model List<Vendor>
@using (Html.BeginForm())
{
<table class="tblData">
<thead>
....
</thead>
<tbody>
for(int i = 0; i < Model.Count; i++)
{
<tr>
<td>@Html.TextBoxFor(m => m[i].SubmittedDate)</td>
<td>@Html.TextBoxFor(m => m[i].StartDate)</td>
</tr>
}
</tbody>
</table>
<input type="submit" value="submit" />
}
发布方法
public void PostClick(List<Vendor> model)
{
/*Some Code */
}
这篇关于将表值从视图传递到控制器MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文