Reputation: 495
I have a view that design view like :
Here i impose some entry validation when click save button I want to display me error message in my expecting display region. How can it possible?
My Controller Action is :
[HttpPost]
public ActionResult Save(COA_ChartsOfAccount oCOA_ChartsOfAccount)
{
try
{
if (this.ValidateInput(oCOA_ChartsOfAccount))
{
COA_ChartsOfAccount oParent = new COA_ChartsOfAccount();
oParent = oParent.Get(oCOA_ChartsOfAccount.ParentHeadID);
if (oCOA_ChartsOfAccount.IsChild)
{
oCOA_ChartsOfAccount.ParentHeadID = oParent.AccountHeadID;
}
else
{
oCOA_ChartsOfAccount.ParentHeadID = oParent.ParentHeadID;
}
oCOA_ChartsOfAccount = oCOA_ChartsOfAccount.Save();
return RedirectToAction("RefreshList");
}
return View(oCOA_ChartsOfAccount);
}
catch (Exception ex)
{
return View(oCOA_ChartsOfAccount);
}
}
Note : I want to make common partial view for error message display. (Like exception error message, validation message, all kind of user notification message)
Upvotes: 0
Views: 5763
Reputation: 1610
With your current set up
To display an error message
In your controller:
catch (Exception ex)
{
TempData["message"] = "Custom Error Messge";
return View(oCOA_ChartsOfAccount);
}
In your view:
<div style="color: red;font-weight:900;">@TempData["message"]</div>
Upvotes: 2