在 ASP.NET MVC 3 (Razor) 项目中,我正在尝试上传图片: View 的相关部分:
@using (@Html.BeginForm( new {enctype = "multipart/form-data" }))
{
<text>Select a file </text>
<input type="file" name="file" />
<input type="submit" value="Upload" />
}
明确声明 enctype 参数“负责”剥离参数部分。例如,如果 URL(打开 View )如下:
mydomain/Controller/Action/id?parameter1=somevalue1
上面表格中的 BeginForm 语句将给出(回发)以下内容:
mydomain/Controller/Action/id
因此剥离了部分: ?parameter1=somevalue1 这是需要的!
我该如何处理?
最佳答案
由于您已经将数据发布到服务器,因此我会将所需的参数信息作为隐藏字段放入表单中。
询问“我可以将此信息集合发送到此 URL 而无需填充其他集合吗?”这个问题
对于查询字符串方法,答案是否定的。我会把它作为一个隐藏字段。
@Html.Hidden("SomeParameter", SomeValue);
关于asp.net-mvc-3 - enctype = "multipart/form-data"的表单发布导致参数无法传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11106784/