如何从控制器(MVC)中的视图中获取下拉列表选定值 [英] How to fetch dropdown selected value from view in controller (MVC)
问题描述
如何从控制器中的视图中获取下拉选择值以添加ModelState错误,因为我们添加了文本框值为null?
if(string.IsNullOrEmpty(employee.Name))
{
ModelState.AddModelError(名称,名称字段是必需的);
}
例如:如果用户选择选择部门,我们将创建一个员工。来自部门下拉列表的值,我们需要添加错误,说明请选择有效的部门
我们如何实现这一目标?
< blockquote>如果你使用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
这篇关于如何从控制器(MVC)中的视图中获取下拉列表选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!