R.Mohammed Asar R.Mohammed Asar - 2 months ago 12x
ASP.NET (C#) Question

Asp.NET MVC -- Fileupload image value shows null values in httppost method

I have a MultipartForms in Which I Could upload an Image and other form values.While, the form values are rightfully received through the FormCollection Property whereas the Upload file always shows the null value in HttpPostedFileBase Property.I go through forums but I couldn't get Where went Wrong. Here, Is What I done Please go through it and Said what Went Wrong.Thanks friend.

enter code here


@using (Html.BeginForm("Create", "StaffRegistration", FormMethod.Post, new { enctype = "multipart/form-data" }))
<input type="file" name="StaffImage" id="StaffImage" />


public ActionResult Create(FormCollection collection,HttpPostedFileBase File)
// TODO: Add insert logic here

StaffRegistration StaffReg = new StaffRegistration();

StaffReg.FirstName = collection["FirstName"].ToString();
StaffReg.LastName = collection["LastName"].ToString();
StaffReg.DateOfBirth = DateTime.Parse(collection["DateofBirth"]);
StaffReg.Nationality = collection["Nationality"].ToString();
StaffReg.Gender = collection["Gender"].ToString();
StaffReg.MaritalStatus = collection["MaritalStatus"].ToString();
StaffReg.BloodGroup = collection["BloodGroup"].ToString();
StaffReg.StaffName = collection["StaffName"].ToString();
StaffReg.MiddleName = collection["MiddleName"].ToString();
HttpPostedFileBase file = Request.Files["StaffImage"];

StaffRegistrationBusSer StaffRegBusSer = new StaffRegistrationBusSer();

return RedirectToAction("Index");


public bool AddStaffRegistraiton(StaffRegistration staffRegistration,HttpPostedFileBase File)
staffRegistration.StaffImage = ConvertToByte(File);

using(SqlConnection Con = new SqlConnection(ConnectionString))
SqlParameter paramImage = new SqlParameter();
paramImage.ParameterName = "@StaffImage";
paramImage.Value = staffRegistration.StaffImage;

return true;

ConvertToByte function:

public byte[] ConvertToByte(HttpPostedFileBase Image)
byte[] imagebyte = null;
BinaryReader Reader = new BinaryReader(Image.InputStream);
imagebyte = Reader.ReadBytes((int)Image.ContentLength);
return imagebyte;


The name of the input tag needs to match the name of your HttpPostedFileBase parameter.

Try renaming the parameter in your Create function to StaffImage, like this:

public ActionResult Create(FormCollection collection, HttpPostedFileBase StaffImage)