我正在使用Asp.Net Core Razor Pages.On开发一个web应用程序,页面模型我有以下属性:
public class SchoolModel : PageModel
{
[BindProperty]
public School SchoolEdit { get; set; }
当我在没有表单posted.How的情况下单击表单上的按钮时,我想更改SchoolEdit(学校类型)的徽标属性。我能做到这一点吗?下面是剃刀页面代码:
@if (Model.SchoolEdit.Logo != null)
{
<button class="btn btn-danger" asp-page-handler="RemovePhoto">
<span aria-hidden="true">×</span>
</button>
}
后来,我定义了下面的Ajax,以便在单击按钮时更改属性,但OnPostRemovePhoto不会被点击!
@section Scripts {
<script>
$(function () {
$("#Click").click(function () {
$.ajax({
type: "POST",
url: "./School?handler=RemovePhoto",
error: function (response) {
alert('hi');
},
success: function (response) {
alert('error');
}
});
});
})
</script>
发布于 2019-02-11 02:54:42
多亏了Asp.Net上的同一个帖子,我才弄明白了这个问题。下面的防伪令牌是missing.The AJAX方法在报头中设置令牌。Here's the answer:
https://stackoverflow.com/questions/54600582
复制相似问题