asp.net mvc - MVC Viewmodel cant access model with View -
how can access viewmodel view? code follows:-,
i have 2 models (using entity framework) have view model of:-
public class viewmodelstory { public ienumerable<tbl_gcb_newsitem> gcb_newsitem { get; set; } public ienumerable<tbl_gcb_itemcomment> comemnts { get; set; } }
my contoller populates models by:-
viewmodelstory.gcb_newsitem = (from in db.tbl_gcb_newsitem i.intitemidentifier.tostring() == storyid select i).singleordefault(); viewmodelstory.comemnts = (from in db.tbl_gcb_itemcomment i.intitemidentifier.tostring() == storyid select i).tolist<tbl_gcb_itemcomment>();
i return model by
return partialview("newsstory", viewmodelstory);
then in view have following declaration
@model viewmodelstory @using gcbsmvc.models
to access model have tried various linq , directly querying model, nothing seems work:- html.displayfor(m =>m.gcb_newsitem. .... viewmodelstory.gcb_newsitem.stritemcategory html.raw(system.web.httputility.htmldecode(viewmodelstory.gcb_newsitem.stritemheadline))
you passing type of model class instead of actual class. try this:
var model = new viewmodelstory(); model.gcb_newsitem = (from in db.tbl_gcb_newsitem i.intitemidentifier.tostring() == storyid select i).singleordefault(); model.comemnts = (from in db.tbl_gcb_itemcomment i.intitemidentifier.tostring() == storyid select i).tolist<tbl_gcb_itemcomment>(); return partialview("newsstory", model);
Comments
Post a Comment