在我的控制器功能的Post方法中,我添加了一些ModelStateError
。一旦添加,我重定向到Get方法。 在Get方法返回視圖時,我希望能夠獲取從Post方法傳遞的錯誤消息並將其添加到Modelstate。在使用RedirectToAction時轉發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");
}
現在已添加的錯誤,我想在下面的函數
[HttpGet]
public ActionResult AttendeeAvailability(Guid appointmentId,Guid attendeeId)
{
.....
Modelstate.AddModelError()//add message passed from post(if any);
return View(model);
}
任何建議,以找回它?
我不認爲ModelState錯誤可以傳遞到不同的動作。 Whate @Pratik建議可以處理這種情況。這是我能找到的[post](http://stackoverflow.com/questions/4642845/asp-net-mvc-how-to-preserve-modelstate-errors-across-redirecttoaction)。 – Nilesh