How to obtain data from a form using method=“post”? How to request it data in my controller?

后端 未结 4 1099
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 05:19

I am trying to obtain data from my html code like the \"acquringCode\", \"cardAcceptor\", and \"merchantId\". I can\'t figure how how to obtain that data in my controller.

4条回答
  •  我在风中等你
    2020-12-22 06:07

    Create a viewModel like this one:

    public class TreventLocationLookupViewModel
    {
        public string InstitutionIdentificationCode {get; set;}
        public string CardAcceptorIdentificationCode {get; set;}
        public string MerchantId {get; set;}
    }
    

    and then use it in your Action like that:

    public ActionResult AddSaveTreventLocationLookup(TreventLocationLookupViewModel model)
    {
    
            AdminProductionServices.TreventLocationLookup treventLocationLookup = Administrator.Models.AdminProduction.TreventLocationLookup.loadTreventLocationLookup(Guid.Empty, Guid.Empty, string.Empty, string.Empty, string.Empty)[0];
    
            treventLocationLookup.acquiringInstitutionIdentifcationCode = model.InstitutionIdentificationCode;
            treventLocationLookup.cardAcceptorIdentificationCode = model.CardAcceptorIdentificationCode;
            treventLocationLookup.merchantId = model.MerchantId;
    
            Administrator.Models.AdminProduction.TreventLocationLookup.addTreventLocationLookup(treventLocationLookup);
    
        return RedirectToAction("SearchTreventLocationLookup", "Prod");
    }
    

    MVC will take care of the binding the request values to the model for you. You should have a read about model binders and validation anyway to get an idea.

提交回复
热议问题