我正在尝试使用ajax来更新我的页面:
@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>
我的购物清单控制器:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(PartialViewModel d)
{
// Add "current group" to each new item and put it in the 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");
}
当我按下我的按钮时,我希望我的文本字段中的数据被发送到控制器,然后将结果发布到页面,但没有任何反应。有什么问题?