【发布时间】:2019-05-07 19:24:20
【问题描述】:
我有一个 ViewModel、Controller 和 View,如下所示
public class H2HViewModel
{
public DateTime EffectiveDate { get; set; }
public byte TransferMethod { get; set; }
public string ListOfSelectedBatchID { get; set; }
}
控制器
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(H2HViewModel model)
{
var detailPayments = db.Payments.Where(x => x.Status == 2).ToList();
foreach (Payment detail in detailPayments)
{
detail.PaymentStatus = 4;
detail.EffectiveDate = model.EffectiveDate;
detail.TransferMethod = model.TransferMethod.ToString();
}
db.SaveChanges();
return RedirectToAction("Dashboard", "User");
}
查看
@model EPayment.Data.ViewModels.H2HViewModel
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.EditorFor(model => model.EffectiveDate, new { @class = "form-control dtpicker" })
<div class="col-md-10">
@Html.RadioButtonFor(model => model.TransferMethod, "AB", new { htmlAttributes = new { @class = "form -control" } }) AB
@Html.RadioButtonFor(model => model.TransferMethod, "BC", new { htmlAttributes = new { @class = "form -control" } }) BC
</div>
<input type="submit" value="Submit" class="btn btn-default"/>
}
当我点击提交按钮时,没有任何反应, 我在 ActionResult Create 上设置了一个断点来调试它,但也没有任何反应。 我参考了这个stackoverflow.com/questions/16443927,并且已经做到了,但是没有用,知道吗?谢谢。
【问题讨论】:
-
您的 post 方法上没有
[ValidateAntiForgeryToken],并且您的 post 方法不返回任何数据! -
对不起,我已经更新了@LazZiya上面的代码
标签: c# asp.net-mvc razor