So, I have a ready-made method that works, and I use it throughout the site:
public PartialViewResult GetBlogEntries(int itemsToTake = 5) { ... return PartialView("_BlogPost", model); }
Now I want to get this from my javascript in JSON form.
public JsonResult GetBlogPostJson() { var blogEntry = GetBlogEntries(1); var lastEntryId = GetLastBlogEntryId(); return Json(new {Html = blogEntry, LastEntryId = lastEntryId}, JsonRequestBehavior.AllowGet); }
The idea should look like this:
$.ajax({ url: '/Blog/GetBlogPostJson', dataType: 'json', success: function (data) { var lastEntryId = data.LastEntryId; var html = data.Html; ... } });
The problem is that this, of course, does not create a row, but a PartialViewResult.
The question is, how can I solve PartialViewResult in html that I can send back using JSON?
Patrick
source share