我在partialview中使用ajax.beginform并将模型发送到控制器进行保存,但是ajax.beginform发送了一个空模型
我的PartialView-表单
@model DataLayer.Product_Comments
@using (Ajax.BeginForm("CreateComment", "Product", FormMethod.Post, new AjaxOptions()
{
OnSuccess = "successComment",
UpdateTargetId = "listComment"
}))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(m => m.ProductID)
<div class="col-md-5">
<div class="form-group">
@Html.TextBoxFor(m => m.Name, new { @class = "form-control", placeholder = "نام خود را وارد کنید" })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.TextBoxFor(m => m.Email, new { @class = "form-control", placeholder = "ایمیل خود را وارد کنید" })
@Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.TextBoxFor(m => m.WebSite, new { @class = "form-control", placeholder = "وب سایت خود را وارد کنید" })
</div>
</div>
<div class="col-md-7">
@Html.TextAreaFor(m => m.Comment, new { @class = "form-control", placeholder = "متن نظر خود را وارد کنید" })
@Html.ValidationMessageFor(model => model.Comment, "", new { @class = "text-danger" })
<input class="btn btn-primary" value="ثبت دیدگاه ارزشمند شما" type="submit">
</div>
<div class="clearfix"></div>
}
我的控制器
[HttpPost]
public ActionResult CreateComment(Product_Comments xlx)
{
if (ModelState.IsValid)
{
xlx.CreateDate = DateTime.Now;
db.Product_Comments.Add(xlx);
db.SaveChanges();
return PartialView("ShowComments", db.Product_Comments.Where(c => c.ProductID == xlx.ProductID));
}
return PartialView(xlx);
}
我在页面上添加了'jquery.unobtrusive-ajax.min.js',但是当我跟踪我的代码时,xlx为空。
您能解释为什么吗?