我无法检索控制器中的值,它返回null。请帮我看看我做错了什么。
下面是我的代码
的Index.aspx
<form id="form1" method="post" action="/Sample/Index" enctype="multipart/form-data">
<div>
<input type="text" id="PcId" value=<%=Model.PcId %> /></div>
<input type="file" value="Browse" id="file"/>
<input type="submit" id="submit" value="Save"/></div>
</form>
在我的控制器中
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
string PcId = Request.Form["PcId"];
List<string> fileConfigData = new List<string>();
if (file != null && file.ContentLength > 0)
{
string FolderPath = mPath.GetFolderPath();
var fileName = Path.GetFileName(file.FileName);
string filePath = Server.MapPath(FolderPath + PcId) + "\\" + fileName;
file.SaveAs(filePath);
}
return view();
}
答案 0 :(得分:4)
尝试在输入字段中添加名称:
<input type="text" id="PcId" name="PcId" value=<%=Model.PcId %>
根据W3C规范,每个表单输入元素都应该指定name属性。否则将不处理该元素。
http://www.w3.org/TR/html401/interact/forms.html#successful-controls