【发布时间】:2018-09-04 19:06:35
【问题描述】:
我的第一个项目是使用 Core 2.0 Razor 页面开始的,我之前对 MVC 5 有一点经验(以前的项目运行良好)。
Razor 页面和 AJAX 的问题很简单:
有一个包含客户列表的页面
使用 AJAX 编辑客户的链接以调用 Razor 部分页面 Customer_editPartial(它将完整的客户表单返回到项目中的模态 DIV)
问题是如何渲染Ajax调用返回的部分页面?如果我从 customer_editPartial.cs 返回一个带有文本的新 json,它正在工作,但无法显示部分页面。
感谢您的帮助。
这里是页面customers.cshtml
<script>
function editCustomer(id) {
$.ajax({
type: "GET",
url: "Customer_editPartial?id=0",
contentType: "application/json",
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
dataType: "json",
success: function (response) {
AjaxCustomer_LoadSuccess(response);
},
failure: function (response) {
alert('Customer content load failed.');
}
})
}
function AjaxCustomer_LoadSuccess(data) {
$('#displayContent').html(data);
}
</script>
<a onclick="editCustomer(0);">Edit customer</a>
Here the ajax return<br />
页面 Customer_editPartial.cshtml
@page
@model UGM_Web.Pages.AHadmin.Customer_editPartialModel
edit partial form
这里是 Customer_editPartial.cs
[ValidateAntiForgeryToken]
public IActionResult OnGet(int? id)
{
return Page();
//return new JsonResult("This is working when i return json text");
}
public void OnPost()
{
}
【问题讨论】:
-
有人可以帮帮我吗?
标签: c# asp.net-mvc asp.net-ajax razor-pages