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 ARank #1,243 · 1.4K reputationPosted May 9, 2016, 1:04 AM EDT
{
// 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 SharmaRank #174 · 13.9K reputationPosted May 5, 2016, 8:28 AM EDT