Hi I'm using Angulajs as front end and ASP.NET WebAPI as backend.
This is my Model class:
public class UserModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
[Required]
[StringLength(50, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 7)]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[Display(Name = "Phone")]
public string PhoneNumber { get; set; }
}
Controller:
// POST api/Account/Register
[AllowAnonymous]
[Route("Register")]
public async Task<IHttpActionResult> Register(UserModel userModel)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
IdentityResult result = await _repo.RegisterUser(userModel);
IHttpActionResult errorResult = GetErrorResult(result);
if (errorResult != null)
{
return errorResult;
}
return Ok();
}
This is my Angular Service:
var _saveRegistration = function (registration) {
return $http.post('http://localhost:26264/api/account/register', registration).then(function (response) {
return response;
});
};
I'm sending payload P.S This is made up payload
registration:{
userName:"UserName",
email: "eamil@emal.com",
password:"password",
confirmPassword:"password",
phone: "9898989898"
}
When I debug I see all the values in payload but when I set debugger at API Controller "register" method field "PhoneNumber" is null. I don't know what wrong I'm doing, please help
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire