且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从控制器(MVC)中的视图中获取下拉列表选定值

更新时间:2022-11-10 19:31:05

如果你使用JQuery Ajax,你的问题的解决方案将变得容易


How to fetch dropdown selected value from view in controller to add ModelState error as we added for textbox values for being null?
if (string.IsNullOrEmpty(employee.Name))
{
ModelState.AddModelError("Name","The Name field is required");
}
Ex:When we are creating an Employee if the user selects "Select Department" value from Department dropdown list,we need to add the error stating "Please select the valid Department"
How do we achieve this?

The solution to your problem will become easy if you make use of JQuery Ajax