There is a certain representation that receives a custom image through <input type="file" value="Добавить аватар" /> and then passes it to an action method, but for some reason, null is always coming to the method, not the image.

Representation:

 @using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.EditorForModel() <label>Повторите пароль</label><br> @Html.Password("Повторите пароль") <br> <br> <input type="file" value="Добавить аватар" /> <br> <br> <input type="submit" value="Зарегестрироваться" /> } 

The action method that processes the submitted form:

 [HttpPost] public ActionResult Registr(User user, HttpPostedFileBase image) { if (image != null) { user.IconUserType = image.ContentType; user.IconUserData = new byte[image.ContentLength]; image.InputStream.Read(user.IconUserData, 0, image.ContentLength); } 

    1 answer 1

    For the successful binding (binding) of the request elements and the action parameters of the method (by default) they must be named the same.

     <input type="file" value="Добавить аватар" name="image"/>