TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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....
Reply
Answers (
1
)
How to create Web API in .Net with Get Method using parametr
State Mangement Techniques