Я заполнил выпадающий список данными из моей базы данных.Однако я не уверен, эффективен ли мой метод или нет.Что я могу сделать, чтобы улучшить это, или метод, который я использовал, безопасен / достаточен?
Я добавил контроллер, viewModel и View ниже.Весь совет очень ценится!
Контроллер:
[HttpGet]
public ActionResult SchedulerIndex()
{
Entities entities = new Entities();
var getJobList = entities.Jobs.ToList();
SelectList list = new SelectList(getJobList, "JobId", "JobName");
ViewBag.jobListName = list;
[HttpPost]
public ActionResult ScheduleInfo(Values model, int JobList1, string Second, string Minute, string Hour, object DayOfMonth, object Month, object DaysOfWeek, int repeatTime)
{
model.Job = JobList1;
Просмотр:
@using (Html.BeginForm("ScheduleInfo", "Scheduler", FormMethod.Post))
{
Html.EnableClientValidation();
<center>
<div style="text-align: center">
<div class="form-group">
<h4>Select a job from the list</h4>
@Html.DropDownList("JobList1", ViewBag.jobListName as SelectList)
</div>
</div>
</center>
ViewModel:
public class Values
{
public List<object> DayOfMonth { get; set; }
public List<object> Month { get; set; }
public List<object> DaysOfWeek { get; set; }
[Required(ErrorMessage = "Enter a number between 0-59!")]
[RegularExpression(@"^(,{0,1}(\b\d\b|[0-5][0-9]|\*+)(-\b\d\b|-[0-5][0-9]){0,1})$", ErrorMessage = "Enter a number between 0-59!")]
public object Second { get; set; }
[Required(ErrorMessage = "Enter a number between 0-59!")]
[RegularExpression(@"^(,{0,1}(\b\d\b|[0-5][0-9]|\*+)(-\b\d\b|-[0-5][0-9]){0,1})$", ErrorMessage = "Enter a number between 0-59!")]
public object Minute { get; set; }
[Required(ErrorMessage = "Enter a number between 0-23!")]
[RegularExpression(@"^(,{0,1}(\b\d\b|[0-1][0-9]|[2][0-3]|\*+)(-\b\d\b|-[0-1][0-9]|-[2][0-4]){0,1})$", ErrorMessage = "Enter a number between 0-23!")]
public object Hour { get; set; }
//public List<SelectListItem> Jobs { get; set; }
public int Job { get; set; }
public List<Values> DofMInfo { get; set; }
public string DofMNo { get; set; }
public int DofMID { get; set; }
public List<Values> MonthInfo { get; set; }
public int monthID { get; set; }
public string monthName { get; set; }
public List<Values> DayInfo { get; set; }
public int dayID { get; set; }
public string dayName { get; set; }
[Required(ErrorMessage ="Enter the number of repeat times. 0 = execute once!")]
public int repeatTime { get; set; }
public bool IsChecked { get; set; }
}