4
在ASP.NET MVC視圖上,我有幾個複選框,一個用於電子郵件地址,另一個用於電話。我想確保至少有一個被選中(兩者都可以被選中,所以單選按鈕並不理想),如果兩者都不是,用紅色邊框突出顯示行,就像文本框帶有驗證功能一樣...ASP.NET MVC數據驗證 - 突出顯示錶格行與文本框
我有其他領域得到驗證正確和CSS正在改變相應的文本框和textareas問題。下面的代碼顯示消息,通知他們必須指定聯繫人偏好的用戶,但不突出顯示該行作爲有一個問題...
截屏 alt text http://i41.tinypic.com/2hcgfew.jpg
VIEW
<table width="100%">
<tr>
<td>
<label>
How would you like us to contact you?
</label>
</td>
</tr>
<tr id="pref_row">
<td>
<span class="bold-text">Email: </span>
<%=Html.CheckBox("EmailDesired")%>
<span class="bold-text">Phone: </span>
<%=Html.CheckBox("PhoneDesired")%>
</td>
</tr>
</table>
控制器
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(ContactUs contactus)
{
ContactUsService svc = new ContactUsService();
// Validation
if (!contactus.EmailDesired && !contactus.PhoneDesired)
ViewData.ModelState.AddModelError("pref_row", "Please specify a contact preference (phone and/or email)!");
if (ViewData.ModelState.IsValid)
{
MessageModel msg = svc.SendRequest(contactus);
return RedirectToAction("Index", msg);
}
else
{
return View();
}
}
怎麼樣一個單選按鈕? – 2009-06-09 01:55:42
丹尼爾 - 必須檢查一個,但兩者都可以檢查。單選按鈕通常用於A或B,而不是A和B ...... – RSolberg 2009-06-09 01:59:34