gpt4 book ai didi

asp.net-mvc - 多页/表单MVC Web应用程序的最佳实践

转载 作者:行者123 更新时间:2023-12-04 09:31:33 25 4
gpt4 key购买 nike

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

收集数据后,将其提交到Web Service/WebAPI。 (无法更改,否则我将使用EF实体)。

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

最佳答案

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

在最后一页上,提交并保存 View 模型。

Controller 代码:

[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。这是我以前成功使用过的一个:

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

关于asp.net-mvc - 多页/表单MVC Web应用程序的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17178164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com