javascript - MVC, how get model property from response viewModel -
iam implementing "show more post" in blogs list following this example
but want make little change , switch viewdata
viewmodel
this relevant code:
private void addmoreurltoviewdata(int entrycount) { viewdata["showmore "] = url.action("index", "messaggi", new { entrycount = entrycount + defaultentrycount }); }
that switch to
viewmodel.showmore = url.action("index", "messaggi", new { entrycount = entrycount + defaultentrycount });
the index action of example:
public actionresult index(int? entrycount) { if (!entrycount.hasvalue) entrycount = defaultentrycount; int totalitems; if(request.isajaxrequest()) { int page = entrycount.value / defaultentrycount; //retrieve page specified page variable page size o defaultentrycount ienumerable<entry> pagedentries = getlatestentries(page, defaultentrycount, out totalitems); if(entrycount < totalitems) addmoreurltoviewdata(entrycount.value); return view("entryteaserlist", pagedentries); } //retrieve first page page size of entrycount ienumerable<entry> entries = getlatestentries(1, entrycount.value, out totalitems); if (entrycount < totalitems) addmoreurltoviewdata(entrycount.value); return view(entries); }
here add lot of code load post db, code think relevant swtich return view("entryteaserlist", pagedentries);
return view(myviewmodel);
after setting blogslist
, showmore
property
but problem in javascript command:
$(function() { addmorelinkbehaviour(); }); function addmorelinkbehaviour() { $('#entryteaserlist #morelink').live("click", function() { $(this).html("<img src='/images/ajax-loader.gif' />"); $.get($(this).attr("href"), function(response) { $('#entryteaserlist ol').append($("ol", response).html()); $('#entryteaserlist #showmore').replacewith($("#showmore", response)); }); return false; }); }
where
$('#entryteaserlist #showmore').replacewith($("#showmore", response));
take viewdata property , use replace link
how can read viewmodel proeprty instead?
wiki
Comments
Post a Comment