在将视图模型传递给后期操作的视图后,视图中的字段不会被填充

时间:2017-04-13 14:29:19

标签: asp.net-mvc-5

嗨,这更像是一个MVC问题。我正在我的MVC应用程序中实现保存功能。我编写了一个HTTPPOST方法来保存记录。当我尝试将viewmodel传递给视图时,我正在修改一个名为requestID的属性。保存请求后检索此请求。当我的视图加载时,我没有看到包含数据的requestid字段。我已正确绑定控件。在post操作期间是否丢失了viewmodel信息。我正在看的是我需要用我保存的最新请求刷新我的观点。

[HttpPost]
public ActionResult Request_Insert(NewRequestViewModel newRequestViewModel)
{

    newRequestViewModel.CompanyCode = "8100";
    newRequestViewModel.RequestStatusCode = "New";
    if (!ModelState.IsValid)
    {
        return null;
    }
    int requestId = requestRepository.CreateRequest(Mapper.Map<Request>(newRequestViewModel));

    newRequestViewModel.RequestID = requestId;


    return View("NewRequestView", Mapper.Map<NewRequestViewModel>(newRequestViewModel));
}

请求字段

@model CC.GRP.MCRequest.ViewModels.NewRequestViewModel
     <div class="form-group">
                        @Html.LabelFor(model => model.RequestID, htmlAttributes: new { @class = "control-label col-md-4" })
                        <div class="col-md-8">
                            <div class="editor-field">
                                @Html.EditorFor(model => model.RequestID, new { htmlAttributes = new { @class = "form-control", style = "width:100%", @readonly = "readonly" } })

                            </div>
                            @Html.ValidationMessageFor(model => model.RequestID, "", new { @class = "text-danger" })
                        </div>
                    </div>

0 个答案:

没有答案