2
我在創建視圖中有一個單選按鈕列表。它在選擇下拉列表時與複選框一起生成。使用mvc3獲取根據數據庫中的值選擇的單選按鈕
@model IEnumerable<Admin.Models.viewmodel>
@foreach (var item in Model)
{
<label>
@Html.CheckBox("User", item.Selected, new { @id = "User" + item.Value, @value = item.Value })
@item.Text
</label>
<label>
@Html.RadioButton("rdnUser" + item.Value.TrimStart(), 1, item.IsSelected,new { @id = "rdnUser"})Primary
</label>
<label>
@Html.RadioButton("rdnUser" + item.Value.TrimStart(), 2,item.IsSelected, new { @id = "rdnUser"})Secondary
</label>
}
Iam將單選按鈕的值保存到表UserMapping中的字段UserType。
當我點擊編輯鏈接,我想根據數據庫值選擇的單選按鈕..
創建一個視圖模型採取複選框,並radiobutton.viewpartial視圖模型數值是: -
public class viewpartial : System.Web.Mvc.SelectListItem
{
public int Values { get; set; }
public bool IsSelected { get; set; }
}
查詢是: -
var query = (from u in UserMapping
where u.UserID == id && u.Active == 1
join f in Financial on u.FinancialID equals f.FinancialID
into c
from d in c.DefaultIfEmpty()
select new viewpartialIFC
{
Text = d.FiName,
Value = SqlFunctions.StringConvert((double)d.FinancialID),
Selected = d.FinancialID == u.FinancialID ? true : false,
Values = u.UserType,
//IsSelected=???
}).Distinct().ToList();
我應該在查詢什麼樣的變化得到單選按鈕選擇..