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?
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.