我有以下控制器。如果發生錯誤但表單數據丟失,則返回視圖。 有沒有人有一個想法,我怎麼可以返回與視圖的表單數據?使用表單數據返回查看
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Register(FormCollection collection)
{
string usrname = collection["UserName"];
string email = collection["Email"];
string password = collection["Password"];
string serial = collection["Serial"];
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
// In a real app, actually register the user now
if (ValidateRegistration(usrname, email, password, password))
{
// Attempt to register the user
MembershipCreateStatus createStatus = MembershipService.CreateUser(usrname, password, email, serial);
if (createStatus == MembershipCreateStatus.Success)
{
//TODO userinformation
datacontext.SaveChanges();
FormsAuth.SignIn(collection["UserName"], false /* createPersistentCookie */);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("_FORM", ErrorCodeToString(createStatus));
//I would like to return the view with the form data
return View();
}
}