ASP.NET antiforgerytoken 表示该对象为空
ASP.NET antiforgerytoken saying that the object is null
我做了一个我们在 class 中做的练习,但我不知道为什么 @Html.AntiForgeryToken()
给我错误
System.NullReferenceException: 'Object reference not set to an
instance of an object.
<form method="post" action="\Files\Upload" enctype="multipart/form-data">
@Html.AntiForgeryToken()
<input type="hidden" value="@Model.Id" name="id" />
<label>Choose photo (,jpg\.png):</label>
<input type="file" name="file" class="form-control" />
<input type="submit" value="Upload Photo" />
</form>
您在操作中忘记 return 反对。
因为您的视图正在调用 属性 @Model.Id
public ActionResult Upload()
{
Test test = new Test();
test.Id = 999;
return View(test);
}
我做了一个我们在 class 中做的练习,但我不知道为什么 @Html.AntiForgeryToken()
给我错误
System.NullReferenceException: 'Object reference not set to an instance of an object.
<form method="post" action="\Files\Upload" enctype="multipart/form-data">
@Html.AntiForgeryToken()
<input type="hidden" value="@Model.Id" name="id" />
<label>Choose photo (,jpg\.png):</label>
<input type="file" name="file" class="form-control" />
<input type="submit" value="Upload Photo" />
</form>
您在操作中忘记 return 反对。
因为您的视图正在调用 属性 @Model.Id
public ActionResult Upload()
{
Test test = new Test();
test.Id = 999;
return View(test);
}