Mua*_*ath 6 ajax jquery asp.net-mvc-4
我在控制器中有这个:
[HttpPost]
public ActionResult Create(Student student)
{ //somecode..
Run Code Online (Sandbox Code Playgroud)
我想从以下提交:
<form method="post" action="/student/create">
<!-- the from contents-->
Run Code Online (Sandbox Code Playgroud)
如何使用Ajax调用提交此函数我需要使用JQuery ajax调用来提交此表单.
我想确保数据类型,谢谢
Moh*_*mar 18
试试这个
var form = $('#formId');
$.ajax({
cache: false,
async: true,
type: "POST",
url: form.attr('action'),
data: form.serialize(),
success: function (data) {
alert(data);
}
});
Run Code Online (Sandbox Code Playgroud)
假设您正在使用剃刀视图,请使用此选项:
@using (Ajax.BeginForm(new AjaxOptions(){
HttpMethod = "POST",
Url = "your controller",
OnComplete = "some client event"
})
{
<fieldset>
<legend>This is a demo form.</legend>
@Html.LabelFor(model => model.Name)
@Html.TextBoxFor(model => model.Name)
<input type="submit" value="Save" />
</fieldset>
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29128 次 |
| 最近记录: |