Hi Team
I am using entity framework and have a property for Time as Timespan, somehow when i used Ado.Net entity model on local machine. autogenerated file for my model for this property was System.Timespan Time {get;set;}// This now currently not saving time as timespan and defaults with 00:00:00 from local database. Any reason for this?
// Model
public TimeSpan Time { get; set; } // This was public system.Timespan Time {get;set;}
// Controller
// Saving functionality public ActionResult SaveIncidentTemplates(Incident_DropDown incident_templates) { if (ModelState.IsValid) { using (TimeLineApplicationDBContext db = new TimeLineApplicationDBContext()) { Incident_Template template = new Incident_Template { Title = incident_templates.Title, Date_Occured = incident_templates.Date.Date.ToString(), Time = incident_templates.Date.TimeOfDay, Description = incident_templates.Description, Assignment_Group = incident_templates.Assignment_Group, Reported_CI = incident_templates.Reported_CI }; try { db.Incident_Template.Add(template); db.SaveChanges(); } catch(Exception ex) { } } } return View(); }
// View
<!--Time--> <div class="form-group"> <input asp-for="Time" id="Time" type="time" class="form-control" value="Time"/> </div> <script> $("#btnSubmit").click(function () { debugger; var Title = $("#Title").val(); var Date = $("#Date").val(); var Description = $("#Description11").val(); var Date_Occured = $("#Date_Occured").val(); var Time = $("#Time").val(); var Assignment_Group = $("#Assignment_Group").val(); var Reported_CI = $("#Reported_CI").val(); alert(Title + Date + Description + Date_Occured + Time + Assignment_Group + Reported_CI ); // Ajax call request transpoted to save values. $.ajax({ type: "POST", url: "/Home/SaveIncidentTemplates?Title=" + Title + "&Date=" + Date + "&Description=" + Description + "&Date_Occured=" + Date_Occured + "&Time=" + Time + "&Assignment_Group=" + Assignment_Group + "&Reported_CI=" + Reported_CI, dataType: "application/json", success: function () { alert("Saved successfully"); } }) }); </script>