I followed an exercise we did in class and I do not know why but @Html.AntiForgeryToken()
is giving me the error
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>
Your forgot to return object in your action.
Because your view is calling property @Model.Id
public ActionResult Upload()
{
Test test = new Test();
test.Id = 999;
return View(test);
}