jquery - Ajax not sending to controller -
i trying use ajax update page:
@using (html.beginform()) { @html.antiforgerytoken() <div class="form-horizontal"> <hr /> @html.validationsummary(true, "", new { @class = "text-danger" }) <div class="form-group"> <div align ="center" class="col-md-12"> @html.editorfor(model => model.youritem.comment, new { htmlattributes = new { @class = "form-control", placeholder ="add item", id="mango" } }) @html.validationmessagefor(model => model.youritem.comment, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div align ="center" class="col-md-12"> <button type="button" id="min_knapp" class="btn btn-default-shoppinglist">add </button> </div> </div> </div> } @if (model != null) { @html.partial("~/views/shoppinglists/_create.cshtml", model.mylist) } <script> $("#min_knapp").click(function() { var v1 = jquery("#mango").val(); jquery.ajax({ url: '@url.action("create","shoppinglists")', method: "post", cache: false, data: { mango: v1 } }).done(function (d) { jquery("#handleliste").text(d); }); }) </script>
my shoppinglistscontroller:
[httppost] [validateantiforgerytoken] public actionresult create(partialviewmodel d) { // add "current group" each new item , put in database d.youritem.groupid = convert.toint32(request.cookies["selectboxvalue"].value); db.shoppinglists.add(d.youritem); db.savechanges(); pv.mylist = db.shoppinglists.tolist(); return partialview("_liste"); }
when press button expecting data textfield sent controller , post result page, nothing happens. wrong?
Comments
Post a Comment