I have a ViewModel, Controller and View like below
public class H2HViewModel
{
public DateTime EffectiveDate { get; set; }
public byte TransferMethod { get; set; }
public string ListOfSelectedBatchID { get; set; }
}
Controller
[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");
}
View
@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"/>
}
when I click the submit button nothing happens, I made a breakpoints on ActionResult Create to debug it, but nothing happened too. I refer to this stackoverflow.com/questions/16443927 , and have done it but it didn't work, any idea? thanks.
You're not specifying where to post that form... Html.BeginForm
can take several parameters . You should be specifying the ActionName
and ControllerName
@using (Html.BeginForm("Create", "Controller", FormMethod.Post))
Note: "Controller" will be the name of your controller.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.