Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 20, 2010 05:23 AM by WilliamSnell
Member
351 Points
550 Posts
Jun 19, 2010 10:57 PM|LINK
I have my form created like this:
and the upload part, in that form: <input type="file" name="calendarUpload" id="calendarUpload" /> <input type="submit" value="Upload Image" />
and the upload part, in that form:
and then the Controller method:
public ActionResult UploadCalendar(HttpPostedFileBase calendarUpload) { calendarUpload.SaveAs(Url.Images("calendar.jpg")); return RedirectToAction("Activities"); }
The variable 'calendarUpload' is always null. Any suggestions?
Star
7702 Points
1099 Posts
Microsoft
Jun 20, 2010 12:45 AM|LINK
You're calling the wrong overload of BeginForm(). Try this instead:
<% using (Html.BeginForm("UploadCalendar", "Home", FormMethod.Post, new {enctype = "multipart/form-data"})) { %>
Jun 20, 2010 05:23 AM|LINK
That was exactly it, thanks! I thought that post was the default action for a form, and didn't wise to that being the cause.
WilliamSnell
Member
351 Points
550 Posts
HttpPostedFileBase always null
Jun 19, 2010 10:57 PM|LINK
I have my form created like this:
and then the Controller method:
public ActionResult UploadCalendar(HttpPostedFileBase calendarUpload) { calendarUpload.SaveAs(Url.Images("calendar.jpg")); return RedirectToAction("Activities"); }The variable 'calendarUpload' is always null. Any suggestions?
levib
Star
7702 Points
1099 Posts
Microsoft
Re: HttpPostedFileBase always null
Jun 20, 2010 12:45 AM|LINK
You're calling the wrong overload of BeginForm(). Try this instead:
<% using (Html.BeginForm("UploadCalendar", "Home", FormMethod.Post, new {enctype = "multipart/form-data"})) { %>WilliamSnell
Member
351 Points
550 Posts
Re: HttpPostedFileBase always null
Jun 20, 2010 05:23 AM|LINK
That was exactly it, thanks! I thought that post was the default action for a form, and didn't wise to that being the cause.