[英]Form not passing POST data to controller
I am passing in a reference to a file, and a string value cardid
. 我正在传递对文件的引用和一个字符串值cardid
。 For some reason when I return the result the cardid
value is null. 由于某些原因,当我返回结果时, cardid
值为null。 However when I view the page the <h3>
header contains the string I expected. 但是,当我查看页面时, <h3>
标头包含我期望的字符串。 What am I doing wrong? 我究竟做错了什么?
HTML view HTML视图
<h3>@Model.CV.Id</h3>
@using (Html.BeginForm("UploadFile", "Tickets", FormMethod.Post, new { cardid=@Model.CV.Id, enctype = "multipart/form-data"}))
{
<input type="file" name="file" />
<input type="submit" value="Upload Attachment" />
}
Controller 调节器
public async Task<IActionResult> UploadFile(string cardid,IFormFile file)
{
......
string res="yay";
return Ok(new {cardid=cardid,res=res });
}
You should include cardid
in your form. 您应该在表单中包含cardid
。 You are simply creating an attribute on <form>
, which does nothing. 您只是在<form>
上创建一个不执行任何操作的属性。
<h3>@Model.CV.Id</h3>
@using (Html.BeginForm("UploadFile", "Tickets", FormMethod.Post, new { enctype = "multipart/form-data"}))
{
<input type="hidden" name="cardid" value="@(Model.CV.Id)" />
<input type="file" name="file" />
<input type="submit" value="Upload Attachment" />
}
You could also include `cardid in the action: 您还可以在行动中加入“心脏”:
Html.BeginForm("UploadFile?cardid=" + Model.CV.Id, "Tickets", FormMethod.Post...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.