I need to Return error message from Controller to View and show it to User.
What i was tried is:
CONTROLLER:
[HttpPost]
public ActionResult form_edit(FormModels model)
{
model.error_msg = model.update_content(model);
ModelState.AddModelError("error", "adfdghdghgdhgdhdgda");
ViewBag.error = TempData["error"];
return RedirectToAction("Form_edit", "Form");
}
VIEW:
@model mvc_cs.Models.FormModels
@using ctrlr = mvc_cs.Controllers.FormController
@using (Html.BeginForm("form_edit", "Form", FormMethod.Post))
{
| @Html.ValidationSummary("error") @Html.ValidationMessage("error") |
@Html.DisplayNameFor(model => model.content_name) @Html.DropDownListFor(x => x.selectedvalue, new SelectList(Model.Countries, Model.dd_value, Model.dd_text), "-- Select Product--") |
|---|
}
Please help me to achieve this.
Please dont give ant links to read.
Abhilash J APosted May 9, 2016, 5:04 AM
{
// check if TempData contains some error message and if yes add to the model state.
if (TempData["error"] != null)
{
ModelState.AddModelError(string.Empty, TempData["error"].ToString());
}
return View();
}
Munesh SharmaPosted May 5, 2016, 12:28 PM