Ramesh kumar

Ramesh kumar

  • NA
  • 1
  • 17.9k

MVC 4-Return error message from Controller -Show in View

Nov 22 2013 1:20 AM
I doing a C# project using Razor in VS2010.(MVC 4).
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))
{
    
        <table>
        <tr>
        <td>       
        @Html.ValidationSummary("error")       
        @Html.ValidationMessage("error")      
        </td>
        </tr>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.content_name)
            @Html.DropDownListFor(x => x.selectedvalue, new SelectList(Model.Countries, Model.dd_value, Model.dd_text), "-- Select Product--")
           
        </th>
    </tr>
</table>
    
<table>
    <tr>
        <td>
            <input  type="submit" value="Submit" />
        </td>
    </tr>
</table>
}

Please help me to achieve this.
Please dont give ant links to read.

Answers (2)