Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpPostedFileBase always remaining null mvc

i know that there is a lot of questions like this, but i read them all and null of them solved my problem. Here below im going to show the code that i have in my view and my controller so that you can have an idea of my code.

View :
<td><% using (Html.BeginForm("Index", "Home", FormMethod.Post, new {enctype = "multipart/form-data"})) { %>
<%: Html.ValidationSummary(true) %>
                <div id="section1"> 
    <div class="editor-label">
        <%: Html.LabelFor(model => model.Name) %>
    </div>
<label for="file">Filename:</label>
        <input type="file" name="myfile" id="File5" value="Choose File Banner1" />
     <p>&nbsp;</p>

And here is my controller:
[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Index(HomeModel model, string submitButton, HttpPostedFileBase myfile)
    {

I cant figure out what mite be the problem.. can someone help me please

like image 549
user2191421 Avatar asked Dec 19 '22 23:12

user2191421


1 Answers

I also had the same problem and I ended up here while looking for an answer. I had forgotten the enctype parameter in the form definition

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
// form
}
like image 160
Memet Olsen Avatar answered Jan 23 '23 03:01

Memet Olsen