c# - Unable to cast object of type 'WhereListIterator`1[Web.Model.Appointment]' to type 'Web.Model.Appointment' -
this code fragment controller
[httppost] public actionresult cancel(string id,formcollection collection) { //this how declare appt cannot seem correctly pass id method //var appt = application.session.getobjectfromoid<appointment>(new objectid(id)); //i trying way instead error var appt = (appointment)application.appointments.where(a=>a.id.equals(collection["id"])); ..... } this error get:unable cast object of type 'wherelistiterator`1[web.model.appointment]' type 'web.model.appointment'.
this view:
<input type="button" value="save" onclick="updatecancel(); return false;" /><button>save</button> and function
function updatecancel() { $('#cancel').ajaxsubmit({ }); } so why getting error? or there way pass model.data.id function can use id instead?
the where-clause returns iterator. select want use instead. i.e., if expect 1 result, can use firstordefault. can use index, [1].
var appt = (appointment)application.appointments.where (a=>a.id.equals(collection["id"])) .firstordefault(); note firstordefault returns null when item not found, sure check result value.
ps: don't need cast there. without (appointment, error in title, should work, because items in list of type appointment.
Comments
Post a Comment