asp.net mvc - how to pass a where statement in a viewbag -


i trying pass statement in viewbag view. trying pass equipment status equals 'in' won't work. wont display condition.

viewbag.equipmentid = new selectlist(db.equipments.where(o => o .equipmentstatus== "in"), "equipmentid", "equipmenttype", hire.equipmentid); 

my view select equipment is:

<div class="form-group">             @html.labelfor(model => model.equipmentid, "equipmentid", new { @class = "control-label col-md-2" })             <div class="col-md-10">                 @html.dropdownlist("equipmentid", string.empty)                 @html.validationmessagefor(model => model.equipmentid)             </div>         </div> 

my hire model is:

  public class hire     {         public int hireid { get; set; }         public int equipmentid { get; set; }         public int purchaseid { get; set; }          [datatype(datatype.date)]         [displayformat(dataformatstring = "{0:yyyy-mm-dd}", applyformatineditmode = true)]         public datetime returneddate { get; set; }          public virtual purchase purchases { get; set; }         public virtual equipment equipments { get; set; }     } 

using viewmodel method says in view "the name 'model' not exist in current context" view:

 <div class="form-group">             @html.labelfor(model => model.equipmentid, "equipmentid", new { @class = "control-label col-md-2" })             <div class="col-md-10">                @html.dropdownlistfor(model => model.equipmentid, model.selectlist)                 @html.validationmessagefor(model => model.equipmentid)             </div>         </div> 

the 'model' in 'model.equipment' underlined error

this controller:

   public actionresult create(int id)         {             var hire = new hire();             purchase purchase = db.purchasess.find(id);             viewhire responsemodel = new viewhire()             {                 purchaseid = purchase.purchaseid,                 equipmentid = hire.equipmentid,                 selectlist = new selectlist(db.equipments.where(o => o.equipmentstatus == "in"), "equipmentid", "equipmenttype", hire.equipmentid),             };                viewbag.purchaseid = new selectlist(db.purchasess, "purchaseid", "purchaseid");             return view(responsemodel );         } 

consider this:

viewbag.equipments = new selectlist(db.equipments.where(o => o .equipmentstatus== "in"), "equipmentid", "equipmenttype"); 

and in view write:

@html.dropdownlistfor(model=>model.equipmentid,(selectlist)viewbag.equipments,string.empty) 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -