Reputation: 212
I have this code to get the list of record from database, in the list of iDConfig there are some columns i wants to get and put it in model to display as table in the view how do i loop through the list and get the wanted columns?
public ActionResult iDeal_Table_Display(Guid? SA=null)
{
var iDConfig = blergo.Get_iDealConfigs(SA, out retStatus, out errorMsg);
ViewBag.iDconfigs = iDConfig;
return PartialView();
}
this are the column in each row the following image is the database columns that i want in iDConfig
using model below
public class iDealModel
{
[Required]
[DisplayName("Product")]
public Guid ProductId { get; set; }
[Required]
[DisplayName("Request Type")]
public Guid RequestTypeId { get; set; }
[Required]
[DisplayName("Sales Agreement Prefix")]
public Guid SaPrefix { get; set; }
[DisplayName("Calendar Code")]
public System.Nullable<System.Guid> CalendarCode { get; set; }
[DisplayName("Cash & Carry")]
public bool CashnCarry { get; set; }
[DisplayName("Free MM")]
public bool FreeMM { get; set; }
[DisplayName("On Contract")]
public bool OnContract { get; set; }
}
Upvotes: 0
Views: 148
Reputation: 3154
Use LINQ to map your DB entity to your model, like this:
var model = iDConfig.Select(ic => new iDealModel {
SaPrefix = ic.PrefixSA,
CalendarCode = ic.CodeCalendar,
CashnCarry = ic.isCashnCarry,
FreeMM = ic.isFreeMM,
OnContract = ic.isOnContract,
ProductId = ic.Product,
RequestTypeId = ic.RequestType
});
Upvotes: 1
Reputation: 27944
You can do:
var product = iDConfig[0].Product
Or something like:
foreach(var ic in iDConfig)
{
//get data like
var product = ic.Product;
In your view you can do something like:
<table>
@foreach(var ic in iDConfig)
{
<tr><td>@ic.Product</td></tr>
}
</table>
Upvotes: 1