Reputation: 136
in request data
json data
I don't know, why it pass null values to api?
Update 1
here is my webui action code
const string URLPREFIX = "api/account";
[HttpPost]
public async Task<IActionResult> Login(LoginModel loginModel)
{
var loginFlag = false;
HttpResponseMessage response1 = await ServiceCall<LoginModel>.postData(URLPREFIX + "/authenticate",loginModel);
if (response1.IsSuccessStatusCode)
{
loginFlag = await response1.Content.ReadAsAsync<bool>();
}
if (loginFlag)
{
return RedirectToAction("Index","Home");
}
else
{
return View();
}
}
update 2
public class LoginModel
{
[Required]
[Display(Name = "Username")]
public string Username { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
}
any try and reply, thanks
Upvotes: 0
Views: 1296
Reputation: 3
You must add [ApiController] in controller level. code is following
[ApiController]
[Route("[controller]")]
public class LoginController : ControllerBase
{
const string URLPREFIX = "api/account";
[HttpPost]
public async Task<IActionResult> Login(LoginModel loginModel)
{
var loginFlag = false;
HttpResponseMessage response1 = await ServiceCall<LoginModel>.postData(URLPREFIX + "/authenticate",loginModel);
if (response1.IsSuccessStatusCode)
{
loginFlag = await response1.Content.ReadAsAsync<bool>();
}
if (loginFlag)
{
return RedirectToAction("Index","Home");
}
else
{
return View();
}
}
}
Upvotes: 0
Reputation: 1694
If you are using Json as a parameter to your controllers, use [formbody] in your web API. It should work. Let me know if it doesn't work.
Upvotes: 1