MVC asp.net核心的WebAPI服务呼叫传递空值

问题描述:

中请求数据MVC asp.net核心的WebAPI服务呼叫传递空值

enter image description here

JSON数据

enter image description here

我不知道,为什么它传递null值API?

更新1

这里是我的Web用户界面的操作代码

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(); 
       } 

      } 

更新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; } 
    } 

任何尝试和回复,谢谢

+1

你能显示你的webapi请求代码吗? –

+0

你能更具体吗? – RajSan

+1

哪里是loginmodel – CodingYoshi

如果你是使用JSON作为参数到您的控制器,请在您的Web API中使用[formbody]。它应该工作。让我知道如果它不起作用。

+0

我使用[frombody]在MVC项目中显示空白页面时单击,但在webApi项目中使用[frombody]它工作良好,谢谢 – RajSan