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; }
感謝您的指導。
舊貨