Hi I’m trying to load the viewcomponent using ajax when the button is click. But the view component does work properly it seems that css and js is not working.
Here is the ajax call for the controller Load component
$.ajax({
url: window.location.origin + "/TestDashbook/LoadComponent",
type: "post",
dataType: "json",
data: { 'dbid' : dbid },
complete: function (result) {
$("#divcontent").empty();
$("#divcontent").html(result.responseText);
}
});
Here is the Controller
[HttpPost]
public async Task<IActionResult> LoadComponent(string dbid)
{
var dashtabcount = "0";
var companyId = "1";
var defaultdashbooklist = await dashbookService.FetchDefaultDashbooks();
var dashbooklist = await dashbookService.FetchDashbooks(companyId);
List<DashbookModelView> dblist = new List<DashbookModelView>();
DashbookModelView dbmodel = dashbooklist.Where(s => s._id.ToString() == dbid).FirstOrDefault();
return ViewComponent("TestMultiDash", new { dashbookModel = dbmodel, dashtabcount = dashtabcount, companyId = companyId });
}
Here is the output
This is what it should look like
2
Answers
You are using the
complete
callback that won’t receive the data you are sending back. What you are looking fore is thesuccess
callback.From spec:
See the jquery documentation for more details.
Try this: