Pass multiple data objects to Controller to View? [Resolved]

Posted by Syedshakeer under ASP.NET MVC on 4/7/2017 | Points: 10 | Views : 581 | Status : [Member] | Replies : 0
I am using LINQ to join multiple model classes and pass the Linq object to View using ViewBag.

I am facing problem while repeating data or binding data

Model Properties:

public class SalesModel
public string CustomerName { get; set; }
public int SSN { get; set; }
public int LicenseId { get; set; }
public int Age { get; set; }
public string City { get; set; }
//Vehicle Sales
public DateTime? SaleDate { get; set; }
public int CustomerId { get; set; }
public int SelecteModle { get; set; }

public ActionResult CreateVehicleSalesView()
var make = objVehicleContext.VehicleMakes;

SalesModel objSalesModle = new SalesModel()
MakesList = new SelectList(make, "MakeId", "Make")

//objSalesModle object is using to bind Make dropdowlist in a view

VehicleDataContext objDataContext = new VehicleDataContext();
var vehcileSalesDetails = from VS in objDataContext.Vehiclesales
join VModel in objDataContext.VehicleModels on VS.ModelId equals VModel.ModelId
join Cus in objDataContext.Customers on VS.customerId equals Cus.customerId
join VMake in objDataContext.VehicleMakes on VModel.MakeId equals VMake.MakeId
select new
Name = Cus.customerName,
age = Cus.Age,
city = Cus.City,
licenseId = Cus.LicesnseId,
make = VMake.Make,
model = VModel.Model,
year = VModel.Year,
saleDate = VS.SaleDate

ViewBag.vehicleSalesDetails = vehcileSalesDetails; //How to pass this data to View?

return View(objSalesModle);

View: I have problem while binding data, How to call Linq column names in a view?

<td>Sale Date</td>
@foreach (var v in ()ViewBag.vehicleSalesDetails)

Syed Shakeer Hussain


(No response found.)

Login to post response