多页/表单MVC Web应用程序的最佳实践 [英] Best practice for a multipage/form mvc web app

查看:59
本文介绍了多页/表单MVC Web应用程序的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ASP.Net MVC& EF5.该模型具有足够多的字段,因此应用程序将需要几个页面来收集所有数据.

I have a project using ASP.Net MVC & EF5. The Model has a large enough number of fields that the app will need several pages to collect all of the data.

一旦收集到数据,它将被提交到Web Service/WebAPI. (无法更改,否则我将使用EF实体.)

Once the data is collected it is submitted to a Web Service/WebAPI. (This can not be changed or I would use EF entities instead).

在填充数据模型时在页面之间持久保存的最佳实践或最佳建议是什么?

What is the best practive or best suggestion for persisting the data model from page to page as it is filled?

推荐答案

您可以创建每个页面都使用的一个ViewModel类(强类型视图),然后仅将未编辑的字段存储在隐藏字段中.您的控制器将有一个操作方法并针对每个步骤进行查看.提交每个步骤后,您都将返回视图(以及视图模型)以进行下一步.

You could create one ViewModel class that each page uses (strongly typed view) and just store the fields that aren't being edited in hidden fields. Your controller would have an action method and view for each step. When each step is submitted you return the View (along with the View Model) for the next step.

在最后一页上,提交并保存视图模型.

On the last page, you submit the View Model and save it.

Contoller代码:

Contoller code:

[HttpPost]
public ActionResult Step1(MyBigViewModel model)
{
     //do work
     return View("Step2", model);
}

[HttpPost]    
public ActionResult Step2(MyBigViewModel model)
{
     //do work
     return View("Step3", model);
}

[HttpPost]
public ActionResult Step3(MyBigViewModel model)
{
     //save here
     return View("Success", model);
}

另一种选择是在单个页面上使用类似于向导"的UI.这是我以前成功使用过的一个:

Another option is to use a "Wizard-like" UI on a single page. Here's one I've used before with success:

https://github.com/mstratman/jQuery-Smart-Wizard

这篇关于多页/表单MVC Web应用程序的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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