比方說,我有這個如何在ASP.NET MVC 2中預選一個單選按鈕?
public class OrganisationData
{
public NavigationData navigationData {get; set; }
}
然後
public class NavigationData
{
public string choice {get;set;}
//other properties omitted
}
我有這對我的看法
<% Using(Html.BeginForm()){%>
<p>
<% = Html.RadioButtonFor(x => x.organizationData.navigationData.choice, "1")%>
</p>
//More choices
<%}%>
第一,用戶得到這種看法我想第一個單選按鈕被預選。
感謝您的幫助。
。我沒有把邏輯放在視圖中,而是使用方法RadioButtonFor的HTMLAttributes爲視圖創建了一個默認值。視圖加載時,您的解決方案不會檢查收音機。 – 2010-07-26 13:41:33
將它設置爲與htmlattributes一起檢查是邏輯在視圖中。如果你說radiobuttonfor不會自動檢查複選框,如果它指向的屬性具有單選按鈕所代表的值,那麼它就像平常一樣扼殺ms代碼。很高興我不使用webforms視圖引擎! :) – 2010-07-26 13:51:49
布魯克:它的工作。 – Richard77 2010-07-26 16:03:07