I choose ASP.NET Web Application and then Web API... I leave the Authentication at "Individual User Accounts" and create the project.

When I add the code below to the index.cshtml page... run it... and click submit. I get a NullReferenceException... this is because the parameter "model' is null.

Any help?... this seems so basic to me... I'm just taking the generated sample and trying to call the api with a form.

--- code where error is happening ---

    public async Task<IHttpActionResult> Register(RegisterBindingModel model)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        // *** NullReferenceException here as "model" is null ***

        var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
        ...

--- form in index.cshtml ---

    <form action="~/api/Account/Register" method="post">
        <table>
            <tr><td>Email</td><td><input type="text" id="Email" value="mail@brianrice.com" /></td></tr>
            <tr><td>Password</td><td><input type="text" id="Password" value="f00tball" /></td></tr>
            <tr><td>ConfirmPassword</td><td><input type="text" id="ConfirmPassword" value="f00tball" /></td></tr>
            <tr><td></td><td><input type="submit" /></td></tr>
        </table>
    </form>

Related posts

Recent Viewed