1

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's create to debug it, but nothing happened.

I refer to this stackoverflow.com/questions/16443927, and have done it but it didn't work, any idea?

2
  • you don't have [ValidateAntiForgeryToken] on your post method, and your post method doesn't return any data! Commented May 8, 2019 at 4:58
  • sory I missed it, I have updated the code above @LazZiya Commented May 8, 2019 at 7:04

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@chaeusangchen can you post the rest of your HTML? Your model is probably not deserializing properly. What type of response do you get back?
Hi @maxshuty, I have updated my html in the code above. I did not get any response

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.