問題背景:ASP.NET MVC - 允許多個單選按鈕選擇,爲什麼?
我在菜單中有兩組單選按鈕。其中一組功能包括2個單選按鈕,允許用戶選擇一組項目以按照「從高到低」或「從低到高」的價格排序和顯示。
第二組單選按鈕允許用戶從3個不同的在線市場搜索結果。
的問題:
目前單選按鈕(價格排序組)的第一組工作正常,如果我點擊「從高到低」那麼單選按鈕將被選中,如果我再選擇'低到高'將被選中。
第二組爲市場的3個單選按鈕導致我的問題。這讓所有三個單選按鈕來進行檢查,而不是僅僅一個,一旦所有選中的用戶無法取消選中它們,如下所示:
驗證碼:
這是我觀看的MarkUp。我正在使用RadioButtonsFor
Razer控件將每個單選按鈕綁定到ViewModel的特定屬性。
<div class="form-group">
<div class="maxPricePad">
<label>@Html.RadioButtonFor(model => model.amazonAndEbay, true, new { id = "amazonEbayBox", @checked = "true" })<img class="originPic" src="@Url.Content("~/Images/amazon.png")" /> <img class="originPic" src="@Url.Content("~/Images/ebay.png")" /> Amazon & Ebay</label>
</div>
</div>
<div class="form-group">
<div class="maxPricePad">
<label>@Html.RadioButtonFor(model => model.amazonOnly, true, new { id = "amazonCheckBox" })<img class="originPic" src="@Url.Content("~/Images/amazon.png")" /> Amazon Only</label>
</div>
</div>
<div class="form-group">
<div class="maxPricePad">
<label>@Html.RadioButtonFor(model => model.ebayOnly, true, new { id = "ebayCheckBox" })<img class="originPic" src="@Url.Content("~/Images/ebay.png")" /> Ebay Only</label>
</div>
</div>
的HomePageVM:
public class HomePageVM
{
public bool highToLow { set; get; }
public bool lowToHigh { set; get; }
public bool amazonAndEbay { set; get; }
public bool amazonOnly { set; get; }
public bool ebayOnly { set; get; }
}
單選按鈕的呈現在Chrome:
<div class="form-group">
<div class=" maxPricePad">
<label>
<input checked="true" data-val="true" data-val-required="The amazonAndEbay field is required." id="amazonEbayBox" name="amazonAndEbay" type="radio" value="True"><img class="originPic" src="/Images/amazon.png"> <img class="originPic" src="/Images/ebay.png"> Amazon & Ebay</label>
</div>
</div>
<div class="form-group">
<div class=" maxPricePad">
<label>
<input data-val="true" data-val-required="The amazonOnly field is required." id="amazonCheckBox" name="amazonOnly" type="radio" value="True"><img class="originPic" src="/Images/amazon.png"> Amazon Only</label>
</div>
</div>
<div class="form-group">
<div class=" maxPricePad">
<label>
<input data-val="true" data-val-required="The ebayOnly field is required." id="ebayCheckBox" name="ebayOnly" type="radio" value="True"><img class="originPic" src="/Images/ebay.png"> Ebay Only</label>
</div>
</div>
任何determing爲什麼我收到的所有3個複選框選擇的幫助將非常感激。
這種方法工作正常,但由於某種原因,Chrome的抱怨[DOM]找到2個要素與非唯一身份 – klaydze