Ich versuche, Formulare ohne Post zurück über Ajax einzureichen .. mein Code funktioniert nichtWie reiche ich Formular über Ajax ein?
was ist falsch in meinem Skript?
i bin neu mich mit Ajax-Skripte ajax..help ..
unten ist mein Code
Anmerkung: Ich habe zwei Tasten einreichen mit in der Einzelansicht. Ich möchte Ajax-Aufruf machen für beide Aktionen einreichen
meiner Ansicht
@model AjaxEF.Models.Customer
@using (Html.BeginForm("Index", "Main", FormMethod.Post,new { id="idForm"}))
{
@Html.EditorForModel()
<br />
<input type="submit" name="save" value="Save" />
<input type="submit" name="cancel" value="Cancel" />
}
<script>
$("#idForm").submit(function (e) {
e.preventDefault(); // avoid to execute the actual submit of the form.
var url = "~/Main/Result"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#idForm").serialize(), // serializes the form's elements.
success: function (data) {
alert(data); // show response from the php script.
}
});
});
</script>
mein Controller
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(Customer obj, string save, string cancel)
{
if (!string.IsNullOrEmpty(save))
{
ViewBag.Message = "Customer saved successfully!";
}
if (!string.IsNullOrEmpty(cancel))
{
ViewBag.Message = "The operation was cancelled!";
}
return View("Result", obj);
}
public ActionResult Result()
{
return View();
}
nicht funktioniert .. .still post zurück passiert – naveen