问题
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" />
}
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
the BeginForm-statement in the form above would give (posting back) the following:
mydomain/Controller/Action/id
thus stripping off the part: ?parameter1=somevalue1 which is needed!
How do i take care of this?
回答1:
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);
回答2:
Digging a little bit deeper i discovered that i can do:
@using (@Html.BeginForm(new{parameter1= Request["parameter1"]}, new {enctype = "multipart/form-data" }))
{
<text>Select a file </text>
<input type="file" name="file" />
<input type="submit" value="Upload" />
}
Notice how the Html.BeginForm differs from the initial.
回答3:
You can try by calling the subit from java script by appeding the parameters to the action example document.forms[0].action="photoprocess.asp?="+
and then submit
来源:https://stackoverflow.com/questions/11106784/form-post-with-enctype-multipart-form-data-causing-parameters-to-not-get-pas