每次Controller的返回值都是null
每次控制器接收空值。我该如何解决这个问题?
网址:http://localhost:45801/Account/Login?ReturnUrl=%2Forder%2Fplaceorder
代码:
[HttpPost]
public async Task<IActionResult>Login(UserLoginVM userLoginVM,string ReturnUrl)
{
if (ModelState.IsValid)
{
var result = await signInManager.PasswordSignInAsync
(userLoginVM.LoginId, userLoginVM.Password, userLoginVM.RememberMe, false);
if(result.Succeeded)
{
if(!string.IsNullOrEmpty(ReturnUrl))
{
return RedirectToAction(ReturnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
ModelState.AddModelError("","Invalid username and password");
}
return View(userLoginVM);
}
Receiving Null value every time to Controller. How can I solve this?
Url: http://localhost:45801/Account/Login?ReturnUrl=%2Forder%2Fplaceorder
Code:
[HttpPost]
public async Task<IActionResult>Login(UserLoginVM userLoginVM,string ReturnUrl)
{
if (ModelState.IsValid)
{
var result = await signInManager.PasswordSignInAsync
(userLoginVM.LoginId, userLoginVM.Password, userLoginVM.RememberMe, false);
if(result.Succeeded)
{
if(!string.IsNullOrEmpty(ReturnUrl))
{
return RedirectToAction(ReturnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
ModelState.AddModelError("","Invalid username and password");
}
return View(userLoginVM);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在
UserLoginVM
之前添加[FromBody]
,在string
之前添加[FromQuery]
,因此您的操作方法符号应该像这样:You need to add
[FromBody]
beforeUserLoginVM
and[FromQuery]
beforestring
, so your action method sign should be like this :您应该向参数添加
[FromQuery]
或[FromBody]
属性。将
[FromBody]
属性添加到参数中,强制 Web API 从请求正文中读取。将
[FromQuery]
属性添加到参数中,强制 Web API 从查询字符串中获取值。You should add
[FromQuery]
or[FromBody]
attribute to the parameters.Adding
[FromBody]
attribute to the parameter, force Web API to read from the request body.Adding
[FromQuery]
attribute to the parameter, force Web API to gets values from the query string.