Pankaj Sharma

Pankaj Sharma

  • NA
  • 40
  • 3.3k

Ajax Helper is not working

Jun 27 2016 4:23 AM
Hello! friends i am trying to use Ajax helper in asp.net mvc project.
 
AddCountries.CsHtml Code is:
 
@model AjaxCall.Models.Countries
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
@using (Ajax.BeginForm("AddCountries","Country", new AjaxOptions {
HttpMethod = "POST",
OnBegin = "OnBeginRequest",
OnSuccess = "OnSuccessRequest",
OnComplete = "OnCompleteRequest",
OnFailure = "OnFailureRequest",
Confirm = "Do you want to Add Country ?"
}))
{
<div class="form-horizontal">
<h4>Countries</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.CountriesName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CountriesName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CountriesName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
 
and   code of AddCountries action is
 
[HttpPost]
public ActionResult AddCountries(Countries objCountries)
{
if (Request.IsAjaxRequest())
{
using (DbconnectionContext obj = new DbconnectionContext())
{
obj.Countries.Add(objCountries);
obj.SaveChanges();
}
}
return View();
}
 
but when i am click on "Creat" Button then postback occur and ajax is not call.
So please solve this issue...
Thanks in advance.... 

Answers (1)