I've researched this issue and can not find a solution. My problem is that in my view, I can not view the properties of my ViewModel (e.g., Model.Supplier.SupplerName). Intellisense will only allow me to go Model.Suppliers, or Model.ToolTypes, or Model.ToolTypesSuppliers . I can not get the properties of each of these models that I included into the ViewModel.
ViewModel:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ToolOrder.Models
{
public class ToolTypeSupplierViewModel
{
public ToolTypeSupplierViewModel(IEnumerable<ToolType> tooltypes, IEnumerable<Supplier> suppliers, IEnumerable<ToolTypeSupplier> tooltypesuppliers)
{
this.ToolTypes = tooltypes;
this.Suppliers = suppliers;
this.ToolTypeSuppliers = tooltypesuppliers;
}
public IEnumerable<ToolType> ToolTypes { get; private set; }
public IEnumerable<Supplier> Suppliers { get; private set; }
public IEnumerable<ToolTypeSupplier> ToolTypeSuppliers { get; private set; }
}
}
Controller:
public ActionResult ListToolTypeSupplierOptions()
{
var _tooltypelist =_repository.FetchAllToolTypeOptions();
var _supplierlist = _repository.FetchAllSupplierOptions();
var _toolstypesupplierlist = _repository.FetchAllToolTypeSupplierOptions();
return View(new ToolTypeSupplierViewModel(_tooltypelist, _supplierlist, _toolstypesupplierlist));
}
View:
@model IEnumerable<ToolOrder.Models.ToolTypeSupplierViewModel>
<table>
<tr>
<th>Supplier</th>
<th>Tool TYpe</th>
<th>Created</th>
<th>Last Modified </th>
</tr>
@foreach (var item in Model.) {
<tr>
<td>
</td>
</tr>
}
</table>
Any help would be appreciated or if any further clarification is required, I can follow up. I apologize if this is somewhat vague, I've been up trying to figure out why I can not pull the the properties of each Model that I've included in my ViewModel. Thank you in advance.
foreachstatement off of theModelor inside the loop off of theitem? In the statement of theforeachyou are only going to get Intellisense for collection types. Then inside the loop if you diditem.then you should see the properties for which ever collection type you chose.