小编Ree*_*ena的帖子

在 MVC 5 模型中提交表单在控制器 post 方法中为空

发布后我得到模型中的列表为空我的模型有一个属性,它是 vwLog 的列表。

public class CreateLogViewModel
{
    public List<vwLog> LogData;
}
Run Code Online (Sandbox Code Playgroud)

鉴于我使用该模型并使用 foreach 循环来分配文本控件中的值

@model CreateLogViewModel

@using (Html.BeginForm("CreateLog", "Log", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
    foreach (var item in Model.LogData)
    {
        <table>            
            <tr>
                <td>
                    @Html.HiddenFor(modelItem => item.LogID)
                    @Html.TextBoxFor(modelItem => item.AgencyBillingCode)
                </td>
                <td>
                    @Html.TextBoxFor(modelItem => item.LicenseNumber)
                </td>
            </tr>
        </table>
    }
    <div class="col-xs-12" align="center">
        <input class="btn btn-default" type="submit" name="Submit" value="Save" id="Submit">
    </div>
}
Run Code Online (Sandbox Code Playgroud)

我的控制器是

在 Get 方法中,我正在分配 LogData 对象中的值,该对象是 vwlog 的集合。

public ActionResult CreateLog(CreateLogViewModel model)
{
   model.LogData …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-5

1
推荐指数
1
解决办法
4951
查看次数

标签 统计

asp.net-mvc ×1

asp.net-mvc-5 ×1