如果我的按钮类型是提交,我如何使用带有 onclick 事件的 JQuery 调用操作结果方法我尝试过这样的操作
$("#btnSave).click(function(e){
e.preventDefault();
@Url.Action("Create","ControllerName");
});
最佳答案
如果您想使用 ajax 提交表单数据,您可以使用 jQuery serialize()
方法来序列化表单并发送。
$(function(){
$("#btnSave").click(function(e){
e.preventDefault();
var _f=$(this).closest("form");
$.post(_f.attr("action"),_f.seriazlize(),function(response){
//do something with response
});
});
});
假设您的按钮位于要提交的表单内,并且其操作属性值设置为“创建操作方法”。
@using(Html.BeginForm("Create","YourControllerName"))
{
<!-- Your other form elements goes here -->
<input type="button" id="btnSave" />
}
关于jquery - 如何防止提交事件并通过 onclick 事件调用 ActionResult Method Create 使用 Jquery ASP.NET MVC 提交表单数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38676495/