Код: Выделить всё
public class MultiPartialViewResult
{
public PartialViewResult? Options { get; set; }
public PartialViewResult? Products { get; set; }
}
< /code>
метод, который получает запрос и возвращает результат < /p>
[HttpPost]
public object TestPage(string date)
{
MultiPartialViewResult multiPartial = new MultiPartialViewResult();
var model = products.Where(x => x.ProducingCountry == "PL").ToList();
var partial = PartialView("_ViewTestPage", model);
multiPartial.Products = partial;
return multiPartial;
}
< /code>
javascript ajax, в $ ('#testpage'). html (result.products); Я должен вставить результат в качестве кода HTML, но я получаю объект
$.ajax({
method: 'post',
url: location.pathname,
data: "data",
success: function (result) {
$('#testPage').empty();
console.log(result);
console.log(result.products);
$('#testPage').html(result.products);
}
})
< /code>
И когда я возвращаю частично, я получаю HTML, мне нужен < /p>
[HttpPost]
public IActionResult TestPage(string date)
{
var model = products.Where(x => x.ProducingCountry == "PL").ToList();
return PartialView("_ViewTestPage", model);
}
< /code>
javascript < /p>
$.ajax({
method: 'post',
url: location.pathname,
data: "data",
success: function (result) {
$('#testPage').empty();
console.log(result);
$('#testPage').html(result);
}
})
Подробнее здесь: https://stackoverflow.com/questions/794 ... viewresult