-1
这是ñasp.net mvc 5应用程序开发使用vb.net 我在视图中使用Ajax.beginform,但在控制器回调请求时,不会将其识别为ajax请求。 下面是视图在视图中使用ajax.beginform,但控制器不会识别为ajax请求
<div Class="modal-dialog">
<div Class="modal-content">
<div Class="modal-header">
<Button type="button" Class="close" data-dismiss="modal" aria-hidden="true"></Button>
<h4 Class="modal-title">Edit Nome</h4>
</div>
@Using (Ajax.BeginForm("Edit", "Nomes", Nothing,
New AjaxOptions With {.HttpMethod = "POST", .OnSuccess = "UpdateSuccess"},
New With {.Class = "form-horizontal", .role = "form"}))
@Html.AntiForgeryToken()
@<div Class="modal-body">
...........
<div class="col-md-offset-2 col-md-20">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" value="Save Changes" />
</div>
</div>
</div>
End using
</div>
</div>
的代码和她是控制器
<HttpPost>
<ValidateAntiForgeryToken()>
Public Async Function Edit(modelNome As NomeVM) As Task(Of ActionResult)
If Not ModelState.IsValid Then
Response.StatusCode = CInt(HttpStatusCode.BadRequest)
Return View(If(Request.IsAjaxRequest(), "Edit", "Edit"), modelNome)
End If
Dim nome As Nome = MaptoModel(modelNome)
dbContext.Nome.Attach(nome)
dbContext.Entry(nome).State = EntityState.Modified
Dim task = dbContext.SaveChangesAsync()
Await task
If task.Exception IsNot Nothing Then
ModelState.AddModelError("", "Unable to update the Nome")
Response.StatusCode = CInt(HttpStatusCode.BadRequest)
Return View(If(Request.IsAjaxRequest(), "Edit", "Edit"), modelNome)
End If
If Request.IsAjaxRequest() Then
Return Content("success")
End If
Return RedirectToAction("Index")
End Function
检查浏览器的网络选项卡,看到什么类型的请求时,它是当你提交表格(xhr或不) – Shyju