I am new to Asp.net MVC
I am trying to make Register , my parameters are Email, Password, Confirm Password .
I don't want to do using ajax. I want to perform using 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. But I cannot do it by submit button. I don't know what changes I have to make in this
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.
@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" />
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.