Click here to Skip to main content
15,886,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have area with name "Admin". In that folder,I have page to create user. I put the validation. When I'm trying to add user, the validation is worked but I cannot submit the form. I pressed on the button no thing happen. If I remove the javascript form the view, I can add the user but without the validation.

I need help

"Admin Area"
============
In the control:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(string Mobile,string Password,string FirstName)
{
ParkingMvcApp.Models.Client client = new Models.Client();
client.Mobile = Mobile;
client.Role = "A";
client.Password = Password;
client.FirstName = FirstName;
client.CreatedDate = DateTime.Now;

//To check if the user already regitser
if (db.Clients.Any(m => m.Mobile == Mobile))
{
ModelState.AddModelError("Mobile", "The mobile already in use");
}

if (ModelState.IsValid)
{
db.Clients.Add(client);
db.SaveChanges();
return RedirectToAction("Index");
}

return View(client);
}

In the view:
============
@model ParkingMvcApp.Models.ClientsMV

@{
ViewBag.Title = "Create";
}

<script src="~/Scripts/jquery-1.10.2.min.js"></script> -------------------->1
<script src="~/Scripts/jquery.validate.min.js"></script> ------------------>2
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>------->3

Create



@using (Html.BeginForm())
{
@Html.AntiForgeryToken()


Create new adminstratoer




@Html.ValidationSummary(true, "", new { @class = "text-danger" })

@Html.LabelFor(model => model.Mobile, htmlAttributes: new { @class = "control-label col-md-2" })

@Html.EditorFor(model => model.Mobile, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Mobile, "", new { @class = "text-danger" })




@Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })

@Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })




@Html.LabelFor(model => model.ConfirmPassword, htmlAttributes: new { @class = "control-label col-md-2" })

@Html.EditorFor(model => model.ConfirmPassword, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ConfirmPassword, "", new { @class = "text-danger" })




@Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })

@Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })


div class="form-group">

<input type="submit" value="Create" class="btn btn-default" />



}


@Html.ActionLink("Back to List", "Index")
Posted
Comments
John C Rayan 6-Oct-15 8:48am    
what version of MVC are you using?
Can I see the whole view chtml?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900