c# - How to exclude a record from the Drop Down List -
i have drop down list 'status' on create view , gets data database meaning data on list not hard coded rather dynamic. have 3 records on status table (i.e.available, unavailable , cancelled). want exclude cancelled record on drop down list have available , unavailable. cancelled status still needed used in separate manner. here codes
controller:
public actionresult create(int roomid) { var room = _db.rooms.single(r => r.id == roomid); viewbag.roomcode = room.roomcode; var statlist = _db.reservationsstatus.tolist(); var selectlist = new selectlist((from s in statlist.tolist() select new { statusid = s.id, statusname = s.name }), "statusid", "statusname"); viewdata["slist"] = selectlist; return view(); }
view:
<div class="editor-field"> @html.dropdownlist("ddstatus", (selectlist)viewdata["slist"]) </div>
any solutions appreciated, thanks.
var selectlist = new selectlist((from s in statlist.tolist() s.name != "cancelled" select new { statusid = s.id, statusname = s.name }), "statusid", "statusname")
... assuming name property string , value cancelled...
Comments
Post a Comment