Hi I am trying to post an image but I must be missing something because all I get is a string in return.Here is my code:
@using( Html.BeginForm("Create", "ProductManager", FormMethod.Post,new{enctype="multipart/form-data"})){
<input type="file" class="text-box single-line" id="ProductImagePath" name="ProductAvatar" />
}
[HttpPost]
public ActionResult Create( FormCollection collection)
{
var imagePosted = collection["ProductAvatar"];
}
imagePosted only returns null.What am I doing wrong?
Have you tried looking at what you’re POSTing to your controller? Turn on Developer Tools / FireBug and preview. In Chrome you can expect to see something similar to the below :
Ensure that name parameter of the file input is the same as the HttpPostedFileBase input argument’s name. Ensure that you don’t have another input with the same name.
Finally, run your project in Debug. Put a breakpoint on your action. Go to Immediate window. Poke around. See if
has anything good for you 😉
Good luck 🙂