Trying to upload a file with ASP.NET MVC

后端 未结 4 692
庸人自扰
庸人自扰 2021-02-10 02:44

I am trying to upload a file with ASP.NET MVC.

The following code work perfectly fine:

// Read in the image data.
byte[] binaryData = null;
HttpPostedFil         


        
4条回答
  •  眼角桃花
    2021-02-10 03:34

    No bloody way :(

    I figured out that answer and it's pretty lame.

    I had to have the argument NAME being identical to the Id/Name values of the input type="file" element!!! (not sure if it's either or both element values ... i didn't check that bit out).

    so this is the answer.

    Html input element. (note the value of the Id/Name)

    
    

    Controller method

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Create([Bind(Include = "Subject, Content")]Post post,
        HttpPostedFileBase imageFileName)
    {
    ...
    }
    

    shees!

提交回复
热议问题