簡體   English   中英

提交按鈕在Razor中不起作用asp.net mvc

[英]Submit Button is not working In Razor asp.net mvc

我有一個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 ,並且已經做到了,但是沒有用,是什么主意? 謝謝。

您沒有指定要在何處張貼該表格... Html.BeginForm可以采用多個參數 您應該指定ActionNameControllerName

@using (Html.BeginForm("Create", "Controller", FormMethod.Post))

注意:“控制器”將是您的控制器的名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM