具有实体框架的mvc3中dropdownlist的必需验证器 [英] Required validator for dropdownlist in mvc3 with entity frame work

查看:81
本文介绍了具有实体框架的mvc3中dropdownlist的必需验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我很想念,我不知道mvc3中dropdownlist所需的验证器.

Hey, i am munish, i don''t know the required validator for dropdownlist in mvc3

推荐答案

你好,想念,

为此,您需要在模型中添加一个关键属性.并将您的下拉列表与该关键属性绑定到视图中.

然后在您在模型中定义的属性上方添加[Required(ErrorMessage =")]属性.请参阅下面的快速示例

在模型中

公共列表< selectedlistitem>值{get; set;}

[Required(ErrorMessage =选择值")]
public int KerProperty {get; set;}


可见

@ Html.Dropdownfor(model => model.KerProperty,Model.Values)
@ Html.ValidationMessageFor(model => model.KerProperty)
Hello munish,

For this you need to add one key property in your model. and bind your dropdownlist with that key property in view.

then add [Required(ErrorMessage="")] attribute above the property which is you have define in model. refer below quick example

In Model

public List<selectedlistitem> Values{get;set;}

[Required(ErrorMessage="Select the Value")]
public int KerProperty{get;set;}


In View

@Html.Dropdownfor(model=>model.KerProperty,Model.Values)
@Html.ValidationMessageFor(model=>model.KerProperty)


这篇关于具有实体框架的mvc3中dropdownlist的必需验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆