Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind model explicitly

in general,i will use the code below to make binding of Customer model,

[HttpPost]
public ActionResult Create(Customer model)
{
  ...
}

now, i want to raise the binding later , not immediately ,like this

[HttpPost]
public ActionResult Create()
{
  //some operations first
  ...
  //binding will start here 
  var model={Bind - To - Customer}
  ...
}

so,how can i achieve that, is it possible ???

Thank much for any suggest

like image 972
simpleman Avatar asked Mar 27 '26 21:03

simpleman


1 Answers

You could use the UpdateModel or TryUpdateModel methods:

[HttpPost]
public ActionResult Create()
{
    //some operations first
    ...
    // binding will start here 
    var model = new Customer();
    UpdateModel(customer);
    ...
}
like image 79
Darin Dimitrov Avatar answered Mar 31 '26 07:03

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!