MVC的新手,希望这会非常简单。我有一个HTML下拉列表,我希望根据需要在联系人表单上设置,但是当我应用数据注释时,我无法按照回复的要求将它启动。默认值是 “”如何根据需要在MVC3中设置下拉列表
这里是我的HTML片段:
<div class="editor-field">
<select name="ContactReason" size="1" class="textBox">
<option value=""></option>
<option value="I have a question about this website">I have a question about this website</option>
<option value="My account is locked">My account is locked</option>
<option value="I am experiencing problems with the website">I am experiencing problems with the website</option>
</select>
@Html.ValidationMessageFor(m => m.ContactReason)
</div>
下面是我的注解我的C#代码。我已经尝试设置必要的属性,甚至范围属性,但似乎都没有办法。
[Required(ErrorMessage = "Your reason for contacting is required.")]
[Range(2, 100,
ErrorMessage = "Your reason for contacting is required.")]
public virtual string ContactReason { get; set; }
感谢您的指导。
旧货