views:

89

answers:

1

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 View();
}
else
{
    return RedirectToAction("Index");
}
A: 

You need to equally store them in TempData and reinstate the controls from the saved values.

Developer Art
@Developer any other way other than using `TempData`
Pandiya Chendur
HTML elements in MVC do not have the luxury of preserving their state like it was in WebForms with control state. You have no alternative but to do it manually. How you do it is up to you but you need to store the input values between requests somewhere. You can drop them into TempData or into Session, depends on what you want.
Developer Art