i'm using mvc5 for my applicatio in this form validation is successfully done and datavalidation will be checked but for invalid data error message is not displayed.
Quote:
my view is like below
@using (Html.BeginForm("TimeSheet", "TimeSheet", FormMethod.Post))
{
@*@Html.AntiForgeryToken()*@
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="row">
<div class="col-sm-3">
Select Date: <input type="text" id="Date" Name="Date" class="form-control" placeholder="Select Date">
@Html.ValidationMessageFor(model => model.Date)
@*<span class="field-validation-valid text-danger"
data-valmsg-for="StudentName" data-valmsg-replace="true">
The Date field is required.
</span>*@
</div>
<div class=" col-sm-3">
Select Employee:
@Html.DropDownListFor(m => m.FullName, Model.EmployeeNamesList, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.FullName)
</div>
<div class="row">
<div class="col-sm-3">
Select InTime:<input type="text" id="Intime" Name="Intime" class="form-control" placeholder="Select InTime">
@Html.ValidationMessageFor(model => model.Intime)
</div>
<div class="col-sm-3">
Select LunchOut Time:<input type="text" id="LunchOutTime" Name="LunchOutTime" class="form-control" placeholder="Select LunchOut Time">
@Html.ValidationMessageFor(model => model.LunchOutTime)
</div>
<div class="col-sm-3">
Select LunchIn Time:<input type="text" id="LunchInTime" Name="LunchInTime" class="form-control" placeholder="Select LunchIn Time">
@Html.ValidationMessageFor(model => model.LunchInTime)
</div>
<div class="col-sm-3">
Select OutTime:<input type="text" id="OutTime" Name="OutTime" class="form-control" placeholder="Select OutTime">
@Html.ValidationMessageFor(model => model.OutTime)
</div>
</div>
<br />
<div class="row text-center">
<input type="submit" value="Submit" style="align-items:center" id="viewdetails" class="btn btn-lg btn-primary" />
</div>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
What I have tried:
my model is:
public class TimeSheet
{
public int ID { get; set; }
public int EmpID { get; set; }
[Required]
[Display(Name = "Select user type:")]
public DateTime Date { get; set; }
[Required]
[Display(Name = "Select user type:")]
public TimeSpan Intime { get; set; }
[Required]
[Display(Name = "Select user type:")]
public TimeSpan LunchOutTime { get; set; }
[Required]
[Display(Name = "Select user type:")]
public TimeSpan LunchInTime { get; set; }
[Required]
[Display(Name = "Select user type:")]
public TimeSpan OutTime { get; set; }
[Required]
public string FullName { get; set; }
public List<System.Web.Mvc.SelectListItem> EmployeeNamesList { get; set; }
}
and my controller code is:
[HttpGet]
public ActionResult TimeSheet()
{
using (SnovaHubEntities entities = new SnovaHubEntities())
{
Models.TimeSheet model = new Models.TimeSheet();
model.EmployeeNamesList = GetEmployeenames();
return View(model);
}
}
public ActionResult ViewTimeSheet()
{
return View();
}
[HttpPost]
public ActionResult TimeSheet(Models.TimeSheet model)
{
if (ModelState.IsValid)
{
}
return RedirectToAction("TimeSheet", "TimeSheet");
}
i don't know what is the error in my code
Quote:
and i don't know about ajax so could you please help to solve this