Hello! friends i am trying to use Ajax helper in asp.net mvc project.
AddCountries.CsHtml Code is:
@model AjaxCall.Models.Countries
@using (Ajax.BeginForm("AddCountries","Country", new AjaxOptions {
HttpMethod = "POST",
OnBegin = "OnBeginRequest",
OnSuccess = "OnSuccessRequest",
OnComplete = "OnCompleteRequest",
OnFailure = "OnFailureRequest",
Confirm = "Do you want to Add Country ?"
}))
{
Countries
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.CountriesName, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.CountriesName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CountriesName, "", new { @class = "text-danger" })
}
@Html.ActionLink("Back to List", "Index")
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....
Vinay SinghPosted Jun 27, 2016, 4:53 AM
jQuery Ajax Cascaded DropdownList in Asp.net MVC Using C#.Net