ASP.NET MVCビューでは、メールアドレス用と電話用の2つのチェックボックスがあります。私は、少なくとも1つがチェックされていることを確認したい(どちらもチェックすることができるので、ラジオボタンは理想的ではない)。もしそうでなければ、テキストボックスのような赤い枠線をハイライト表示する...ASP.NET MVCデータ検証 - テーブル行とテキストボックスをハイライト表示
私は正しく検証されている他のフィールドを持っており、それに応じてテキストボックスやテキストエリアに問題があるとCSSが変化しています。以下のコードは...それらが接触選好を指定する必要があり、ユーザに知らせるメッセージを表示するが、問題を有するものとして行を強調表示しない
スクリーンショット 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>
CONTROLLER
[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();
}
}
何のラジオボタンについては? –
Daniel - 1つをチェックする必要がありますが、両方をチェックすることができます。ラジオボタンは、一般的にAとBのどちらかであり、AとBの両方ではありません。 – RSolberg