It is na asp.net mvc 5 app developped useing vb.net I use Ajax.beginform in the view but the controller when it retuns the request, does not recognize as an ajax request. Here is the code for the view
<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>
And her is the code for the controller
<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