Reputation: 725
I'm trying to load partial page contents with jquery.load() method it is loading content but not loading styles. I have searched internet but couldn't found any solution. I'm sharing what i have done so far.
JQUERY:
$(function () {
var site = site || {};
site.baseUrl = site.baseUrl || "";
$(document).ready(function (e) {
$(".partialContents").each(function (index, item) {
var url = site.baseUrl + $(item).data("url");
if (url && url.length > 0) {
$(item).load(url, function (response, status, xhr) {
if (status == "error") {
alert(xhr.status);
}
return false;
});
}
});
});
});
View:
<div class="owl-carousel owl-carousel5">
<span class="partialContents" data-url="@Url.Action("LoadNew","Home")"></span>
</div>
Controller Action:
public async Task<ActionResult> LoadNew()
{
var viewModel = new CategoryViewModel();
viewModel.Products = await db.Products.Include(c => c.Reviews).Include(c => c.CategoryContents).Include(c => c.Affiliates).ToListAsync();
return PartialView("_NewProducts", viewModel);
}
Upvotes: 0
Views: 331
Reputation: 435
As you have mentioned in comments that you have referenced css in Layout, you have to return View instead of PartialView. So,
public async Task<ActionResult> LoadNew()
{
var viewModel = new CategoryViewModel();
viewModel.Products = await db.Products.Include(c => c.Reviews).Include(c => c.CategoryContents).Include(c => c.Affiliates).ToListAsync();
return View("_NewProducts", viewModel);
}
should do the work.
Upvotes: 1