Redirect to current view on error in asp.net mvc?
I use TempData["message"]
which internally uses session.... It works for me but when i do a
return RedirectToAction("Create");
my other values are not restored because i am redirecting to Create
view... Any suggestion how to retain the values of textboxes in the view.....
if (!regrep.registerUser(reg))
{
TempData["message"] = string.Format("{0} already exists", reg.EmailId);
return RedirectToAction("Create");
}
else
{
return RedirectToAction("Index");
}
I used this but still it doesn't get redirected to my last view holding the values of my textboxes...
reg.UserName = collection["UserName"];
reg.OrgName = collection["OrgName"];
reg.Address = collection["Address"];
reg.EmailId = collection["EmailId"];
reg.Password = collection["Password"];
reg.CreatedDate = System.DateTime.Now;
reg.IsDeleted = Convert.ToByte(0);
if (!regrep.registerUser(reg))
{
ViewData["message"] = string.Format("{0} already exists", reg.EmailId);
return Vi开发者_开发技巧ew();
}
else
{
return RedirectToAction("Index");
}
You need to equally store them in TempData
and reinstate the controls from the saved values.
精彩评论