Databinding in ASP.NET MVC Core

stemmen
0

Ik probeer te lezen van HTML vormen enkele gegevens. Ik erin geslaagd om het te doen in ASP.NET MVC, maar niet in ASP.NET MVC CORE. Alle hulp wordt gewaardeerd! Haim

Deze CSHTML code op ASP.NET MVC (werkte prima):

@using (Html.BeginForm(Login, Account)){
<form class=form-group action=Login method=post>
        <input name=AccountAddressTxt type=text class=form-control  required=required id=AccountAddress placeholder=Enter Your Account   Address style=width:50% onclick=SetOx()>
        <br />
        <input name=AccountPasswordTxt type=password class=form-control required=required id=AccountprivateKey placeholder=Enter Your Account Private Key style=width:50%>
         <input id=loginBtn type=submit class=btn btn-success style=width:50% ; value=  Login>
</form>

En de data binding (werkte prima):

namespace RealEstate-Web_app.ModelsBinders
{

public class AccountBinder: IModelBinder
{
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        HttpContextBase objContext = controllerContext.HttpContext;
        String _accountAddress = objContext.Request.Form[AccountAddressTxt];
        String _accountPassword = objContext.Request.Form[AccountPasswordTxt];

        Account obj = new Account()
        {
            AccountAddress = _accountAddress;
            AccountPassword = _accountPassword;
        };
        return obj; 
    }
}

}

Rechts in de controller (werkte prima):

[HttpPost]
public IActionResult Login([ModelBinder(typeof(AccountBinder))] Account  acc)
{
    return View(Login, acc);
}

Maar in ASP.NET MVC CORE Ik krijg een andere methode met geen idee wat te doen:

...   
using Microsoft.AspNetCore.Mvc.ModelBinding;

namespace RealEstate_Web_app.ModelBinders
{
    public class AccountBinder : IModelBinder
    {
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
          //What am I suppose to do here?

        }
    }
}
De vraag is gesteld op 24/10/2019 om 12:57
bron van user
In andere talen...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more