开发者

Redirect to current view on error in asp.net mvc?

开发者 https://www.devze.com 2022-12-31 02:07 出处:网络
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 v

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消