Код: Выделить всё
public partial class EmployeeInfo
{
[DisplayName("First Name")]
[Required(ErrorMessage = "First Name is required")]
public string FirstName { get; set; }
[Required(ErrorMessage = "Job Title is required.")]
[DisplayName("Job Title")]
public virtual JobTitleLookup JobTitleLookup { get; set; }
}
public class JobTitleLookup
{
public int JobTitleLookupId { get; set; }
public string Title { get; set; } = null!;
public virtual List EmployeeInfos { get; } = new List();
}
Код: Выделить всё
public async Task Index()
{
jobTitle = await _Reassign.GetJobTitle();
ViewData["Jobs"] = new SelectList(jobTitle, "JobTitleLookupId", "Title");
}
Код: Выделить всё
public async Task GetJobTitle()
{
return await _ackContext.JobTitleLookup
.OrderBy(c => c.Title).ToListAsync();
}
Код: Выделить всё
--Please select--
Код: Выделить всё
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(EmployeeInfo info)
{
if (info.JobTitleLookupId ==0)
{
var validationMessage = "Job Title is required";
this.ModelState.AddModelError("JobTitleLookupId", validationMessage);
}
if (ModelState.IsValid)
{
}
return RedirectToAction(nameof(Index));
}
Любая помощь будет высоко оценена.
Подробнее здесь: https://stackoverflow.com/questions/792 ... ng-viewbag
Мобильная версия