I need to bind the anonymous type output to viewmodel to pass it on view. the need is to i have to bind the checkbox with the model value i am using join to fetch the value but dont know how to pass it to view. my join query is
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();
my viewModel is
public class costViewModel
{
public int CostId { get; set; }
public string serviceName { get; set; }
public string ServiceTypeValue { get; set; }
public string ServiceCost { get; set; }
}
I need to bind the CostId , serviceName ,ServiceTypeValue ,ServiceCost to the view model to pass it in the view
the retrieve the model on view is
@foreach (var item in Model)
{
<input type="checkbox" name="@item.serviceName" id="@item.serviceName" value="@item.ServiceCost">@item.
}
please help.