如果您希望它们能够关闭浏览器并稍后继续,您将希望使用cookie来存储用户的进度。如果不知道你的完整项目,很难提供一个确切的解决方案,但这肯定会对你有所帮助。
public ActionResult Signup()
{
//The cookie could be stored in the format: partnumber_databaseid
//An example cookie would look like 1_24
if (request.Cookies["SingupProgress"] != null)
{
var part = request.Cookies["SignupProgress"].ToString().Split('_')[0];
var id = request.Cookies["SignupProgress"].ToString().Split('_')[1];
//Eg if the cookie stored number "1" as part, the returned view would be "Part2"
//Return the stored part number plus one, as the part number will represent which part they have already completed
string ViewName = "Part" + part + 1;
return View(ViewName);
}
else
{
//If the cookie doesn't exist, that means the user has not made any sign up progress
//Direct them to the first signup part
return View("Part1");
}
}
public ActionResult Part2()
{
//Direct the user to this action once they have clicked next on the Part 1 view
//Create the class to store the progress data.
//You also need this to extract the Unique ID for the cookie
ProgressClass Progress = new ProgressClass(/*Your data*/);
//Store the progress into the database
db.StoreProgressData();
db.Save();
//Get the unique ID that you just saved into the database
int Id = Progress.Id;
HttpCookie ProgressCookie = new HttpCookie("SignupProgress", Id + "_2");
}
//Once they reach part 3 your final link can direct them to a register action, which creates the account and saves it to a database
您可以以cookie或隐藏窗体值的形式将值返回给用户。这样,用户的状态将由用户保存,而不是由Web服务器保存。当用户提交下一步的请求时,该请求会携带该ID。 (如果没有,服务器会再次启动用户。)除非绝对必要,否则我会避免在Web服务器会话中维护任何状态。让状态由页面或数据库来执行。 – David 2015-04-04 00:39:03
@David似乎是一个好主意,我更倾向于一个cookie,但我认为隐藏的领域可能是一个更好的解决方案,我可以将它从控制器1传递到控制器3。 – 2015-04-04 00:41:24
Cookie可以完成同样的事情。这一切都归结于您期望的用户体验。如果用户需要在一个会话中浏览整个流程,那么将其作为表单值保留在页面上就可以了。如果用户可以放弃会话,关闭他们的浏览器,稍后再回来返回,那么cookie会更合适。这似乎并不是仅仅在网站上注册的可能用例。 – David 2015-04-04 00:42:57