Gaurav Raj

Gaurav Raj

  • NA
  • 475
  • 88.2k

data validation not work in mvc.. please see my code.....

Aug 24 2018 4:04 AM
this is my create view
 
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
<h4>EmployeeTable</h4>
<hr />

@*null, new { @class = "form-control valid", @data_val = "true", @data_val_required = "Billing Address is required" }*@
<div class="form-group">
@Html.LabelFor(model => model.Emp_Name, new { @class = "control-label col-md-2", @data_val = "true", @data_val_required = "Please Enter The Name" })
<div class="col-md-10">
@Html.EditorFor(model => model.Emp_Name)
@Html.ValidationMessageFor(model => model.Emp_Name)
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.Emp_Salary, new { @class = "control-label col-md-2" , @data_val = "true", @data_val_required = "Please Enter The Name" })
<div class="col-md-10">
@Html.EditorFor(model => model.Emp_Salary)
@Html.ValidationMessageFor(model => model.Emp_Salary)
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.Emp_No, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Emp_No)
@Html.ValidationMessageFor(model => model.Emp_No)
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

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

this is my modal
 
public class EmployeeModels
{

public int Emp_Id { get; set; }
[Required(ErrorMessage = "Name is required.")]
public string Emp_Name { get; set; }
public int Emp_Salary { get; set; }
public int Emp_No { get; set; }
this is my controller
 
public ActionResult Create(EmployeeModels emps)
{
try
{
// TODO: Add insert logic here
EmployeeTable emp = new EmployeeTable();
emp.Emp_Name = emps.Emp_Name;
emp.Emp_Salary = emps.Emp_Salary;
emp.Emp_No = emps.Emp_No;
cs.da.EmployeeTables.InsertOnSubmit(emp);
cs.da.SubmitChanges();

return RedirectToAction("Index");
}
catch
{
return View();
}
 
validation are not working
 please are help me guys
 

Answers (1)