-1

In the Post method of my controller's function I have added some ModelStateError. Once added I Redirect to the Get method. In Get method when I return the view, I want to be able to fetch the error message passed from Post method and add it to Modelstate.

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult AttendeeAvailability(params params)
    {            
        ...
        ...
        if (some statement)
        {
            ModelState.AddModelError(string.Empty,Resource.message);
            return RedirectToAction("someaction", new { response.AppointmentId, response.AttendeeId });
        }

        return RedirectToAction("someaction", "somecontroller");
    }

now the error that was added, I want to retrieve it in following function

    [HttpGet]
    public ActionResult AttendeeAvailability(Guid appointmentId,Guid attendeeId)
    {
        .....
        Modelstate.AddModelError()//add message passed from post(if any);
        return View(model);
    }

Any suggestions??

Cybercop
  • 8,475
  • 21
  • 75
  • 135
  • I dont think ModelState Error can be passed on to a different action. Whate @Pratik suggested would be the way you can handle this scenario. Here is one [post](http://stackoverflow.com/questions/4642845/asp-net-mvc-how-to-preserve-modelstate-errors-across-redirecttoaction) I could find. – Nilesh Mar 24 '14 at 11:28

1 Answers1

0

Then you have to use TempData, or session. Add error message to it and display it in the View.

//In Controller
string text = TempData["text"] as string;
//In View
@ViewContext.TempData["text"] 
Pratik Bhoir
  • 2,074
  • 7
  • 19
  • 36