日期:2014-05-17  浏览次数:20377 次

MVC 3 传递 List 数据 到 Controller
想从view 传递一个table 到 controller
请问Controller怎么写?
代码如
@foreach (var item in Model) {
    <tr>
        <td>@Html.DisplayFor(modelItem => item.CustomerCode)</td>       
        <td>
            @Html.DisplayFor(modelItem => item.CustomerName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.CompanyName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Region)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Country)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.City)
        </td>
</tr>

------解决方案--------------------
传list大概方式如下

前台

<input type="checkbox" name="Interestings" value="1" id="i01" /><label for="i01">美食</label>
<input type="checkbox" name="Interestings" value="2" id="i02" /><label for="i02">唱歌</label>
<input type="checkbox" name="Interestings" value="3" id="i03" /><label for="i03">蹦迪</label>

后台

public ActionResult Home(List<string> Interestings)
{
}

------解决方案--------------------
如果Table的行、列是固定的,自定义一个Model就行了,如果行、列不固定,那就只能写Js拼成字符串放在隐藏控件里,到Controller或底层方法里再去拆分了