MVC - 表格完成后的确认页面 [英] MVC - confirmation page after completion of form

查看:48
本文介绍了MVC - 表格完成后的确认页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在向导样式表单的末尾创建一个确认页面。我遇到的问题是,外键没有保留在表单上输入的值。下面是我的代码示例。



这是表单的视图(Form / Edit.cshtml):

I need to create a confirmation page at the conclusion of a wizard style form. The issue I have is, the foreign keys are not remaining populated with the values entered on the form. Below is a sample of my code.

This is the form's view (Form/Edit.cshtml):

<script>
function showReview() {
Review('@Url.Action("Review", HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString())', $("#Confirmation"));
    }

function Review(url, target) {
$.post(url, $("form").serialize(), function(data) {
        target.html(data);
    });

}
</script>
 @using (Html.BeginForm("Edit", "Form", FormMethod.Post, new Dictionary<string, object> { { "id", "FormId" } }))
        {
@Html.LabelFor(m => m.LastName)
@Html.EditorFor(m => m.LastName)
@Html.ValidationMessageFor(m => m.LastName)

@Html.LabelFor(m => m.FirstName)
@Html.EditorFor(m => m.FirstName)
@Html.ValidationMessageFor(m => m.FirstName)

@Html.DropDownList("SuffixID", (IEnumerable<SelectListItem>) ViewBag.Suffix)
}





这是我的控制器(FormController.cs):



This is my controller (FormController.cs):

[HttpPost]
public virtual ActionResult Review(Person model)
{
     return View("Parts/Review", model);
}







这是确认视图(Parts / Review.cshtml):




This is the confirmation view (Parts/Review.cshtml):

<div id="Confirmation">
@Html.DisplayTextFor(m => m.LastName), 
@Html.DisplayTextFor(m => m.FirstName)
@Html.DisplayTextFor(m => m.SuffixLookup.Name)
</div>





当我打开调试器时,model.SuffixLookup为null 。 model.SuffixId包含正确的值。保存数据后,EF模型会正确返回model.SuffixLookup内容。我无法在确认之前保存数据,我必须在加载确认视图之前以某种方式刷新模型。



请帮助...我一直在搜索所有一天的解决方案。我不觉得这应该很难弄清楚但是对MVC来说是新手,我已经挣扎了足够长的时间。



TIA!



When I turn on the debugger, model.SuffixLookup is null. The model.SuffixId contains the correct value. After I save my data, the EF model does come back with the model.SuffixLookup content correctly. I can't save the data before the confirmation, I have to somehow refresh the model before loading the confirmation view.

Please help...I have been searching all day for a solution. I don't feel this should be hard to figure out but being new to MVC, I have struggled long enough.

TIA!

推荐答案

#Confirmation));
}

功能评论(网址,目标){
("#Confirmation")); } function Review(url, target) {


.post(网址,


(< span class =code-string> form)。serialize(),function(data){
target.html(data );
});

}
< / script >
@using(Html.BeginForm( 编辑 表单,FormMethod.Post,字典<字符串,对象> {{ id FormId}}))
{
@ Html.LabelFor(m = > m.LastName)
@ Html.EditorFor(m = > m.LastName)
@ Html.ValidationMessageFor(m = > m.LastName)

@ Html.LabelFor(m = > m.FirstName)
@ Html.EditorFor(m = > m.FirstName)
@Html .ValidationMessageF或(m = > m.FirstName)

@ Html.DropDownList( SuffixID,(IEnumerable< SelectListItem>)ViewBag.Suffix)
}
("form").serialize(), function(data) { target.html(data); }); } </script> @using (Html.BeginForm("Edit", "Form", FormMethod.Post, new Dictionary<string, object> { { "id", "FormId" } })) { @Html.LabelFor(m => m.LastName) @Html.EditorFor(m => m.LastName) @Html.ValidationMessageFor(m => m.LastName) @Html.LabelFor(m => m.FirstName) @Html.EditorFor(m => m.FirstName) @Html.ValidationMessageFor(m => m.FirstName) @Html.DropDownList("SuffixID", (IEnumerable<SelectListItem>) ViewBag.Suffix) }





这是我的控制器(FormController.cs):



This is my controller (FormController.cs):

[HttpPost]
public virtual ActionResult Review(Person model)
{
     return View("Parts/Review", model);
}







这是确认视图(Parts / Review.cshtml):




This is the confirmation view (Parts/Review.cshtml):

<div id="Confirmation">
@Html.DisplayTextFor(m => m.LastName), 
@Html.DisplayTextFor(m => m.FirstName)
@Html.DisplayTextFor(m => m.SuffixLookup.Name)
</div>





当我打开调试器时,model.SuffixLookup为null 。 model.SuffixId包含正确的值。保存数据后,EF模型会正确返回model.SuffixLookup内容。我无法在确认之前保存数据,我必须在加载确认视图之前以某种方式刷新模型。



请帮助...我一直在搜索所有一天的解决方案。我不觉得这应该很难弄清楚但是对MVC来说是新手,我已经挣扎了足够长的时间。



TIA!



When I turn on the debugger, model.SuffixLookup is null. The model.SuffixId contains the correct value. After I save my data, the EF model does come back with the model.SuffixLookup content correctly. I can't save the data before the confirmation, I have to somehow refresh the model before loading the confirmation view.

Please help...I have been searching all day for a solution. I don't feel this should be hard to figure out but being new to MVC, I have struggled long enough.

TIA!


这篇关于MVC - 表格完成后的确认页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆