我有一个初始化为dto的ViewModel。我想从邮递员发送带有其值的json对象,但c#对象不能接受值,并且设置为null。我该怎么办?
public class RegisterUserVm
{
public UserDto User { get; set; }
public RegisterUserVm()
{
User = new UserDto();
}
}
public class UserDto
{
public int Id { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Email { get; set; }
public string Telephone { get; set; }
public string Password { get; set; }
}
[HttpPost]
[Route("RegisterUser")]
public async Task<ActionResult<UserDto>> RegisterUser([FromBody] RegisterUserVm vm)
{
var registeredUser = await userBusiness.RegisterUser(new RegisterUserCommand
{
User = vm.User
});
return registeredUser.Result;
}
答案 0 :(得分:-1)
[HttpPost]
[Route("RegisterUser")]
public async Task<IActionResult> RegisterUser([FromBody] RegisterUserVm vm)
{
var registeredUser = await userBusiness.RegisterUser(new RegisterUserCommand
{
User = vm.User
});
var resultModel = registeredUser.Result.ToResultModel();
return Ok(resultModel);
}