Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to upload image in mvc3.
but when i submit the form model property file is not getting the file information
iam using input tag as follows

@Html.TextBoxFor(model=>model.File,new {type="file"})

how to solve above problem
please any body help me

Thanks in Advance
Posted

1 solution

Make sure you have the enctype on the form set to multipart/form-data

What data type is model.File ?

Check this out : Implementing HTTP File Upload with ASP.NET MVC[^]

I'm editing this so I can show code. You will need to post your code if you want specific help, but I just whipped up a quick solution that worked for me, here's my code:

The Model:
C#
public class MyModel
   {
       public HttpPostedFileBase MyFile { get; set; }
   }


The View:
C#
@model FileUploadTest.Models.MyModel

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
    <head>
        <title>title</title>
    </head>
    <body>
        <div>
              @using (Html.BeginForm("PostFile", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
              {
                  <div>
                      Upload file: @Html.TextBoxFor(m => m.MyFile, new { Type="file"})
                      <p>
                          <input type="submit" value="go"/>
                      </p>
                  </div>
              }
        </div>
    </body>
</html>


The controller:
C#
public ActionResult PostFile(MyModel myModel)
       {
           return this.View();
       }


NOTE: I didn't do anything in the controlller, only set a breakpoint and made sure the value was being posted back and it was. I included the controller action here so you could make sure you were passing your model into it with the post back.

For further help you will really need to post your own code so we can see what you're doing.
 
Share this answer
 
v2
Comments
[no name] 22-Oct-13 9:17am    
it is httppostedfilebase.already
i have given encypt =multipart/form-data

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900