我坚持这种基本问题。 我创建视图模型是为了能够从两个表传递到视图数据:
型:
public class InvoiceReportViewModel
{
public class CurrencyAndWeatherViewModel
{
public IEnumerable<loads> Loadss { get; set; }
public invoices CurrentInvoice { get; set; }
}
}
控制器:
var loadsss = db.loads.Where(x => x.reportid == inv.reportid).ToList();
var modeli = new CurrencyAndWeatherViewModel { Loadss = loadsss, CurrentInvoice = inv };
return View("Invoice", modeli);
视图:
@model app.Models.InvoiceReportViewModel
<div class="container-fluid">
@{ foreach (var item in Model.Loadss)
{
}
总是告诉我:
Severity Code Description Project File Line Suppression State
Error CS1061 'InvoiceReportViewModel' does not contain a definition for 'Loadss' and no accessible extension method 'Loadss' accepting a first argument of type 'InvoiceReportViewModel' could be found (are you missing a using directive or an assembly reference?) 38_Views_Accounting_Invoice.cshtml C:UserszhovnsourcereposBKNappViewsAccountingInvoice.cshtml 10 Active
您应该对视图中的模型使用相同的Type
:
@model app.Models.CurrencyAndWeatherViewModel
<div class="container-fluid">
@{
foreach (var item in Model.Loadss)
{
}
}
</div>