我需要将匿名类型输出绑定到viewmodel才能在视图上传递它。我需要将复选框与模型值绑定在一起,我正在使用join来获取值,但不知道如何将其传递给视图。我的加入查询是
var v = (from pd in ge.Costs
join od in ge.Services on pd.ServiceId equals od.ServiceId
join ct in ge.ServiceTypes on pd.ServiceTypeId equals ct.ServiceTypeId
where pd.ServiceTypeId.Equals(2)
select new
{
pd.CostId,
od.serviceName,
ct.ServiceTypeValue,
pd.ServiceCost
}).ToList();
我的viewModel是
public class costViewModel
{
public int CostId { get; set; }
public string serviceName { get; set; }
public string ServiceTypeValue { get; set; }
public string ServiceCost { get; set; }
}
我需要将CostId,serviceName,ServiceTypeValue,ServiceCost绑定到视图模型,以在视图中传递它
在视图上检索模型是
@foreach (var item in Model)
{
<input type="checkbox" name="@item.serviceName" id="@item.serviceName" value="@item.ServiceCost">@item.
}
请帮忙。
不要让您的选择查询匿名,只需将您的选择与viewModed一起传递
var v = (from pd in ge.Costs
join od in ge.Services on pd.ServiceId equals od.ServiceId
join ct in ge.ServiceTypes on pd.ServiceTypeId equals ct.ServiceTypeId
where pd.ServiceTypeId.Equals(2)
select new costViewModel()
{
CostId = pd.CostId,
serviceName = od.serviceName,
ServiceTypeValue = ct.ServiceTypeValue,
ServiceCost = pd.ServiceCost
}).ToList();
view(v);
然后在视图模型中传递v
并在查看页面上使用
@model IEnumerable<project.ViewModel.costViewModel>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句