Niall Gallagher
asked on
ValidationSummary is not displaying
Hi Experts,
I have done this multiple times and it usually works with no problems but for the life of me I can figure out what I'm doing wrong this time.
I'm calling my action to enter data into the DB but first I run validation on it and I know that it is failing validation as I have first name and last name as required.
I can watch the 2 messages being attached as it runs in debug mode but when the page is displayed the is no validation summary
Here is the top of the view
I use jquery while passing the data to the action but I have done this multiple times before. The problem is probably staring me in the face but I just can't see it.
Any help would be greatly appreciated.
Thanks in advance
I have done this multiple times and it usually works with no problems but for the life of me I can figure out what I'm doing wrong this time.
I'm calling my action to enter data into the DB but first I run validation on it and I know that it is failing validation as I have first name and last name as required.
public ActionResult Create([Bind(Include ="F_Name,L_Name,HireDate,LAN_ID,Office_ID")] Employee e)
{
try
{
HRRepository RR = new HRRepository();
if(!ModelState.IsValid)
{
var allerrors = ModelState.Values.SelectMany(v => v.Errors).ToArray();
foreach (ModelError error in allerrors)
{
ModelState.AddModelError("", error.ErrorMessage.ToString());
}
return View("Index");
}
else
{
RR.Enter_NewHire(e);
ViewBag.ShowPartial = true;
return View("Index");
}
}
catch(Exception ex)
{
return View("Error", new HandleErrorInfo(ex, "App", "Create"));
}
I can watch the 2 messages being attached as it runs in debug mode but when the page is displayed the is no validation summary
Here is the top of the view
@using (Html.BeginForm("Create", "NewHires", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(false, "Please Correct Errors")
<div id="divmain" style="margin-left:10em;">
<fieldset>
I use jquery while passing the data to the action but I have done this multiple times before. The problem is probably staring me in the face but I just can't see it.
Any help would be greatly appreciated.
Thanks in advance
ASKER
When putting the error message in the validation-summary you do not put in a name.
You used to have to put in string.Empty() but in MVC 4 (or possibly 3) they changed it so you just had to put in ""
You used to have to put in string.Empty() but in MVC 4 (or possibly 3) they changed it so you just had to put in ""
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This solution works good to show the user that the data did not validate on client side which would do my job because it is an intranet site.
Open in new window