asp.net mvc - MVC3 Razor ViewBag.Model not making into the Page -
i have modified model system i've inherited, , reason viewbag.model not making page. i've reverted code before started tinkering, , still no luck.
the call view follows:
public virtual actionresult edit(long id) { var _news = _newsrepository.getnewsbyid(id); viewbag.model = automapper.mapper.map<news, newsmodel>(_news); viewbag.model.currentnewsimagefile = configsettings.hostdomainname + configsettings.newsimagebasepath + _news.image_file; return view(); }
the view has following code:
@model mymodels.models.newsmodel @{ bool iscreate = model == null || model.id == 0; viewbag.title = iscreate ? "add news" : "edit news"; }
the problem "model" null in view code... have missed? missing fundamental here?
when tracing through actionresult code, right until return view()
debug inspector correctly shows model containing expect too.
you need return view(themodel)
. if don't pass model view()
doesn't know do.
however, i'm confused code have listed, seem trying put model viewbag? viewbag shouldn't contain model.
i think code want is:
public virtual actionresult edit(long id) { var _news = _newsrepository.getnewsbyid(id); var model = automapper.mapper.map<news, newsmodel>(_news); model.currentnewsimagefile = configsettings.hostdomainname + configsettings.newsimagebasepath + _news.image_file; return view(model); }
Comments
Post a Comment