简体   繁体   English

如何使用Asp.net MVC 5在基于令牌的身份验证Web API中使用提交按钮注册登录?

[英]How to register login using submit button in token based authentication web api using Asp.net MVC 5?

I am new to Asp.net MVC 我是Asp.net MVC的新手

I am trying to make Register , my parameters are Email, Password, Confirm Password . 我正在尝试进行注册 ,我的参数是电子邮件,密码,确认密码

I don't want to do using ajax. 我不想使用ajax。 I want to perform using submit button . 我想使用submit button执行。 I tried below code on my partial view 我在部分视图上尝试了以下代码

@using ProTest.Models
@model RegisterBindingModel

@Html.BeginForm("Register", "Account"){ 
    @Html.TextBoxFor(si => si.Email, new {@class = "form-control",@id = "txtEmail" })
    @Html.TextBoxFor(si => si.Password, new { @class = "form-control", @id = "txtPassword", @type="password" })
    @Html.TextBoxFor(si => si.ConfirmPassword, new { @class = "form-control", @id = "txtConfirmPassword", @type = "password" })

    <input type="submit" class="btn btn-sm btn-primary btn-rounded" value="Signup" id="btnSignup" />
}

below method is created when I create the project MVC with Web api, I can register using ajax. 当使用Web api创建项目MVC时,将创建以下方法,我可以使用Ajax注册。 But I cannot do it by submit button. 但是我不能通过提交按钮来做到这一点。 I don't know what changes I have to make in this 我不知道我必须对此做出什么改变

AccountController 的AccountController

// POST api/Account/Register
[AllowAnonymous]
[Route("Register")]
public async Task<IHttpActionResult> Register(RegisterBindingModel model)
{
    if (!ModelState.IsValid)
    {
        return BadRequest(ModelState);
    }

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

    IdentityResult result = await UserManager.CreateAsync(user, model.Password);

    if (!result.Succeeded)
    {
        return GetErrorResult(result);
    }

    return Ok();
}

You can change in Html.BeginForm parameter like this, it work well in my side. 您可以像这样在Html.BeginForm参数中进行更改,它在我这一方面工作得很好。

@using (Html.BeginForm("","api/Account/Register")) {
       @Html.TextBoxFor(si => si.Email, new { @class = "form-control", @id = "txtEmail" })
       @Html.TextBoxFor(si => si.Password, new { @class = "form-control", @id = "txtPassword", @type = "password" })
       @Html.TextBoxFor(si => si.ConfirmPassword, new { @class = "form-control", @id = "txtConfirmPassword", @type = "password" })

        <input type = "submit" class="btn btn-sm btn-primary btn-rounded" value="Signup" id="btnSignup" />
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在基于 cookie 身份验证的 asp.net mvc 项目中向 web api 添加令牌身份验证 - How to Add token authentication to web api in cookie authentication based asp.net mvc project 如何在ASP.Net MVC中基于令牌的身份验证中也注册用户电话号码? - How to register user phone number also in Token based authentication in ASP.Net MVC? 如何在使用ASP.NET MVC Web API时注册已知类型以进行序列化 - How to register Known Types for serialization when using ASP.NET MVC Web API ASP.NET 5 Web Api基于令牌的身份验证 - ASP.NET 5 Web Api Token Based Authentication 如何使用ASP.NET 5 MVC 6保护Web API - How to protect a Web API using ASP.NET 5 MVC 6 使用Asp.net MVC 6和Web Api进行身份验证 - Authentication with Asp.net MVC 6 and Web Api 在ASP.NET MVC5中使用自定义登录进行表单身份验证 - Using Custom Login for forms authentication in asp.net mvc5 如何使用模式中的提交按钮提交我的表单? (ASP.NET MVC) - How can i submit my form using the submit button in a modal? (ASP.NET MVC) ASP.NET Web API + ASP.NET MVC身份验证 - ASP.NET Web API + ASP.NET MVC Authentication 使用Windows身份验证和OWIN的ASP.NET MVC5 / AngularJS / Web API应用程序 - ASP.NET MVC5/AngularJS/Web API app using Windows Authentication and OWIN
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM