Hi Team
I need some help, i have this following logic and it saved to my local database, need help immediately when a user sends a submit button the data sends an email notification. Detailing data being saved and user can view. This is my current code
// Controller
// saving values to the database records. 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, //what? it was a comment Description = incident_templates.Description }; try { db.Incident_Template.Add(template); db.SaveChanges(); } catch(Exception ex) { } } } return View(); }
// Model
public class Incident_DropDown { public string Title { get; set; } public string Description { get; set; } public string Date_Occured { get; set; } public TimeSpan Time { get; set; } public string Assignment_Group { get; set; } public DateTime Date { get; set; } public string Reported_CI { get; set; } }
// View
<form action="/" method="post"> <div class="form-group"> <input asp-for="Title" id="Title" type="text" class="form-control" value="" /> </div> <div class="form-group"> <input id="Description11" type="text" class="form-control" value="" /> </div> <div class="form-group"> <input asp-for="Date" id="Date" type="Date" class="form-control" value="" /> </div> <div class="form-group"> <button type="button" class="btn btn-primary" id="btnSubmit">Submit</button> </div> </form> <script> $("#btnSubmit").click(function () { debugger; var Title = $("#Title").val(); var Date = $("#Date").val(); var Description = $("#Description11").val(); alert(Title + Date + Description); // Ajax call request transpoted to save values. $.ajax({ type: "POST", url: "/Home/SaveIncidentTemplates?Title=" + Title + "&Date=" + Date + "&Description=" + Description, dataType: "application/json", success: function () { alert("Saved successfully"); } }) }); </script>