表单提交与ENCTYPE ="的multipart / form-data的"造成参数不获得通过 [英] Form Post with enctype = "multipart/form-data" causing parameters to not get passed
问题描述
在一个ASP.NET MVC 3(剃刀)项目我试图上传图片:
视图的相关部分:
In an ASP.NET MVC 3 (Razor) project i 'm trying to upload a picture: the relevant part of the 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(开口视图)是以下
stating explicitly the enctype parameter is "responsible" for stripping off the parameter part. For example, if the URL (opening the view) was the following:
mydomain/Controller/Action/id?parameter1=somevalue1
在形式BeginForm-上述声明将使(回发)以下内容:
the BeginForm-statement in the form above would give (posting back) the following:
mydomain/Controller/Action/id
从而剥离部分:?!参数1 = somevalue1这是需要
thus stripping off the part: ?parameter1=somevalue1 which is needed!
我如何照顾这?
推荐答案
既然你已经发布的数据到服务器我把表单所需要的参数信息隐藏字段。
Since you're already posting data to the server I'd put the required parameter information in the form as hidden fields.
问这个问题:我可以这样收集的信息发送到这个网址,无需填充其他集合?
Asking the question "Can I send this collection of information to this URL without needing to populate other collections?"
通过查询字符串的方法,答案是否定的。我把它作为一个隐藏字段。
With the querystring method the answer is no. I'd put it as a hidden field.
@Html.Hidden("SomeParameter", SomeValue);
这篇关于表单提交与ENCTYPE =&QUOT;的multipart / form-data的&QUOT;造成参数不获得通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!