asp.net mvc - 'object' does not contain a definition for... Creating anonymous model object in view -
i'm trying create anonymous type in view file pass partial view, i'm getting following error:
'object' not contain definition 'resultset'
i'm trying pass anonymous object model view so:
@html.partial("~/views/shared/components/pagination.cshtml", new { resultset = model.userplaces });
i've had bit of search around, , answers have mentioned cannot create anonymous types in controller , pass view (https://stackoverflow.com/a/7652765/495328) i'm not creating anonymous type in controller in example.
also, other questions seem indicate issue appears because of error in view, , not related anonymous type @ all. don't believe issue in case, working fine when model passed view model.userplaces
not new { resultset = model.userplaces }
my pagination.cshtml view file looks like:
@if (model.resultset.totalresults > model.resultset.limit) { <nav> <ul class="pagination" data-base-url="@model.resultset.basepageurl"> <li> <a href="#" onclick="tracklas.pagination.loadresults('prev', this); return false;" aria-label="previous"> <span aria-hidden="true">«</span> </a> </li> @for (int = 1; < ((model.resultset.totalresults / model.resultset.limit) + 1); i++) { <li class="@(i == 1 ? "active" : "")" data-page-num="@i"><a href="#" onclick="tracklas.pagination.loadresults('@i)', this); return false;">@i</a></li> } <li> <a href="#" onclick="tracklas.pagination.loadresults('next', this); return false;" aria-label="next"> <span aria-hidden="true">»</span> </a> </li> </ul> </nav> }
interestingly, if put break-point on the first line in pagination.cshtml file, can inspect 'model' object in watch window. try model.resultset
following message in watch window:
the expression cannot evaluated. common cause of error attempting pass lambda delegate.
the reason i'm trying accomplish expand anonymous type include front-end references (elements ids, etc) , want specify these in view, rather in controller typed model object. figured why anonymous types created/is useful for.
Comments
Post a Comment