c# - Passing two query's to a view, no GetEnumerator -


i have bookings class populated entity framework, want run different queries against table , return them both view. ive read using class combind them having trouble getting work...

thanks help

error

foreach statement cannot operate on variables of type 'itapp.models.bookings' because 'itapp.models.bookings' not contain public definition 'getenumerator'

class

namespace itapp.models {     public class bookings     {         public list<tblbooking> bookedin { get; set; }         public list<tblbooking> bookedout { get; set; }     } } 

usage (for testing im using same query both, use in/out queries after)

var tblbookings = d in db.tblbookings.include(t => t.equipment).include(t => t.tbluser)                     (d.equipment.bookable == true ) &&                             (d.equipment.deleted == false) &&                             (d.equipment.decommissiondate == null || d.equipment.decommissiondate == dateblank1 || d.equipment.decommissiondate == dateblank2)                     select d; bookings bookings = new bookings(); bookings.bookedin = tblbookings.tolist(); bookings.bookedout = tblbookings.tolist();  return view("loaned", bookings); 

view

@model itapp.models.bookings @foreach (var item in model) {     foreach (var initem in item.bookedin)     {         <td>             @html.displayfor(modelitem => initem.tbluser.fullname)         </td>         <td>             @html.displayfor(modelitem => initem.bookfrom)         </td>               <td>             @html.displayfor(modelitem => initem.bookto)         </td>       } } 

you changed question. error solution might removing outer foreach loop, one:

@foreach (var item in model) 

as view model not ienumerable.

so inner loop

foreach (var initem in model.bookedin) 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -