c# - The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery -
i want record db hidden=false , id got in browser. please see code , prepare me, much (i searched can not prepare error). action:
public actionresult detail(int id = 0) { var item = db.destinations.where(i=>i.hidden==false && i.id==id); if (item==null) { homecoming httpnotfound(); } homecoming view(item); } my view:
@model vtt.models.destination @{ viewbag.title = "detail"; } <div class="white"> <h1>@model.name</h1> @html.raw(model.description) </div> and error:
model item passed dictionary of type 'system.data.entity.infrastructure.dbquery`1[vtt.models.destination]', dictionary requires model item of type 'vtt.models.destination'.
currently you're trying pass in model query, whereas view expecting single model object. check nullity pointless, - result of where never null... it's query.
instead, should utilize singleordefault, *executes query, getting single value:
var item = db.destinations.singleordefault(i => !i.hidden && i.id == id); now check nullity useful (because singleordefault homecoming null if there no results) , type right view.
c# asp.net-mvc linq
No comments:
Post a Comment