Objective: It is necessary to implement automatic insertion of the current date and time when adding an entry to the table (IDStudent).
public class Students { [Key] [HiddenInput(DisplayValue = false)] public int StudentsId { get; set; } public string IDStudent { get; set; } public string Name { get; set; } public string Notes { get; set; } public string datetime { get; set; } /* **???** */ } Data in db is already there and you just need to add or create a new IDStudent.
@using (Html.BeginForm()) { @Html.TextBoxFor(m => m.IDStudent, new { @class = "form-control"}) @Html.ValidationMessage("IDStudent") <div class=""> <input type="submit" value="Сохранить" class="btn btn-primary" /> </div> } When you save IDStudent, the date and time are automatically saved.
From where to get the date and time? In the controller and deliver it as a string to the database or through sql? How to implement it and how easier?
Only cognize programming and mvc. Thank you in advance for your response!