ASP.NET CORE练习 - 附录 - 报错解决方法
Request.Form报错InvalidOperationException: Incorrect Content-Type
ASP.NET CORE报错:
InvalidOperationException: Incorrect Content-Type

原因,使用了
Request.Form
例如:
Request.Form["httitle"]

错误代码:
public void OnGet()
{
string m_title =Request.Form["httitle"];
}

解决方法:需要在方法OnPost中使用
public void OnPost()
{
string m_title =Request.Form["httitle"];
}


解决方法2,不是在OnPost中需先判断Request.ContentType:
public void OnGet()
{
if (Request.ContentType == "application/x-www-form-urlencoded")
{
string m_title = Request.Form["httitle"];
}
}


版本:.net 7

.cshtml代码:

@page
@model HovertreeWebApp.Pages.hovertreeModel

<form method="post">
标题:<input type="text" name="httitle" />
<br />

<input type="submit" name="htsubmit" value="提交" />

</form>
收藏 列表

评论: