I need to return a PartialView through API call
this is my Ajax Request
$.ajax({
url: 'sampleurl',
type: 'POST',
headers: { 'litium-request-context': JSON.stringify(window.__litium.requestContext) },
cache: false
}).done(function(html) {
debugger;
var cart = $('.js-minicart');
if (cart.length && $(html).length) {
cart.html($(html).html());
}
});
In the Api controller I created an object of home controller and tried to return the parital view
public class HomeController : ControllerBase
{
private readonly RequestModelAccessor _requestModelAccessor;
public HomeController(HomeViewModelBuilder builder, AuthorizationService authorizationService,
RequestModelAccessor requestModelAccessor, HeaderViewModelBuilder<HeaderViewModel> headerViewModelBuilder)
{
_requestModelAccessor = requestModelAccessor;
}
[HttpPost]
public ActionResult Index()
{
var currentArea = _requestModelAccessor.GetWebsiteArea();
var partialView = PartialView($"~/Areas/{currentArea}/Views/Shared/Framework/_partialView.cshtml");
return partialView;
}
}
but in ajax I am not getting the html, instead I am getting the Object.
So I tried another method, in the ajax method for url: I called
site.axd/controller/method
and it reaches the method in controller, but _requestModelAccessor is disposed and I am not able to continue.
Need some help here.