我正在使用Asp.Net Core Razor Pages开发Web应用程序。在页面模型上,我具有以下属性:
public class SchoolModel : PageModel
{
[BindProperty]
public School SchoolEdit { get; set; }
我想在不发布表单的情况下单击表单上的按钮时更改SchoolEdit(类型为School)的Logo属性。如何实现此目的? 这是剃须刀的页面代码:
@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>