更新时间:2023-02-25 16:59:10
您需要在MVC6明确使用FromBody如果您正在使用JSON
You need to explicit use FromBody on MVC6 if you are using json
public JsonResult Login([FromBody]LoginViewModel model)
修改
我觉得你混合不同的错误。我会尽力来形容你应该如何提出请求:
I think you are mixing different errors. I will try to describe how you should make the request:
内容类型的必须:应用程序/ JSON
content-type must be: application/json
您请求主体的必须 JSON格式(如JasonLind建议):
your request body must be in JSON format (as JasonLind suggested):
{
UserName: 'Test',
Password: 'Test',
RememberMe: true
};
这是你应该看到检查的要求(通过镀铬调试工具F12)时,或使用一个请求检查就像小提琴手。
this is what you should see when inspecting the request (via chrome debugger tools F12) or using a request inspector like fiddler.
如果你看到一些在用户名=测试与放大器的形式;密码=测试和放大器;了rememberMe = TRUE
,那么你就错了,这是形式的格式
If you see something in the form of UserName=Test&Password=Test&RememberMe=true
then you are doing it wrong, that's form format.
您不需要模式
变量。如果你看到你的要求有一个包装,那么你应该将其删除。
you don't need the model
variable. if you see your request with a "wrapper" then you should remove it.