this is my create view
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@*null, new { @class = "form-control valid", @data_val = "true", @data_val_required = "Billing Address is required" }*@
@Html.LabelFor(model => model.Emp_Name, new { @class = "control-label col-md-2", @data_val = "true", @data_val_required = "Please Enter The Name" })
@Html.EditorFor(model => model.Emp_Name)
@Html.ValidationMessageFor(model => model.Emp_Name)
@Html.LabelFor(model => model.Emp_Salary, new { @class = "control-label col-md-2" , @data_val = "true", @data_val_required = "Please Enter The Name" })
@Html.EditorFor(model => model.Emp_Salary)
@Html.ValidationMessageFor(model => model.Emp_Salary)
@Html.LabelFor(model => model.Emp_No, new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Emp_No)
@Html.ValidationMessageFor(model => model.Emp_No)
}
@Html.ActionLink("Back to List", "Index")
this is my modal
{
@Html.AntiForgeryToken()
EmployeeTable
@*null, new { @class = "form-control valid", @data_val = "true", @data_val_required = "Billing Address is required" }*@
@Html.LabelFor(model => model.Emp_Name, new { @class = "control-label col-md-2", @data_val = "true", @data_val_required = "Please Enter The Name" })
@Html.EditorFor(model => model.Emp_Name)
@Html.ValidationMessageFor(model => model.Emp_Name)
@Html.LabelFor(model => model.Emp_Salary, new { @class = "control-label col-md-2" , @data_val = "true", @data_val_required = "Please Enter The Name" })
@Html.EditorFor(model => model.Emp_Salary)
@Html.ValidationMessageFor(model => model.Emp_Salary)
@Html.LabelFor(model => model.Emp_No, new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Emp_No)
@Html.ValidationMessageFor(model => model.Emp_No)
}
@Html.ActionLink("Back to List", "Index")
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; }
}
{
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();
}
}
{
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
Jignesh KumarPosted Aug 24, 2018, 4:21 AM