帖子

时间:2018-02-09 13:45:56

标签: asp.net-mvc null viewmodel

问题是,当点击提交按钮时,我总是在控制器动作方法中收到null。任何帮助将不胜感激。 提前致谢    这是我的观点

<div class="box-body">
    <table class="">
        <thead>
            <tr>
                <th>
                    <label>Employee Name</label>
                </th>
                <th>
                    <label>Remarks</label>
                </th>
                <th>
                    <label>Absent</label>
                </th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.employeeAttendance)
            {
                <tr>
                    <td>
                        @Html.HiddenFor(modelitem => item.EId)
                        @Html.HiddenFor(modelitem => item.Date)
                        @Html.DisplayFor(modelitem => item.EName)
                    </td>
                    <td>
                        @Html.EditorFor(modelitem => item.Remarks, new { @class = "form-control" })
                    </td>
                    <td>
                        @Html.EditorFor(modelitem => item.Status, new { @class = "form-control" })
                    </td>
                </tr>
            }
        </tbody>
    </table>
</div>
<div class="form-group">
    <div class="col-md-12 text-center">
        <input type="submit" value="Create" class="btn btn-primary" /> |
        @Html.ActionLink("Back to List", "Index")
    </div>
</div>

这是我的控制器操作方法

public async Task<ActionResult> Create(EmployeeAttendance empAttendance)
    {
        if (ModelState.IsValid)
        {
            //Logic here
        }
        return View(empAttendance);
    }

这是我的ViewModel

    public class EmpAttendanceViewModel
{
    public bool Status { get; set; }

    public string Remarks { get; set; }

    public DateTime Date { get; set; }

    public int EId { get; set; }

    public string EName { get; set; }
}

这是我的自定义视图

    public class EmployeeAttendance
{
    public IEnumerable<EmpAttendanceViewModel> employeeAttendance { get; set; }
}

问题是,当点击提交按钮时,我总是在控制器动作方法中收到null。任何帮助将不胜感激。 提前致谢

0 个答案:

没有答案
相关问题