开发者

MVC 3 fileupload dialog

开发者 https://www.devze.com 2023-03-25 16:20 出处:网络
I think those tags pretty much says what i\'m asking.. I have been struggling with file upload. What I need to achieve is open a dialog for file upload and save it to database, so nothing too fancy.

I think those tags pretty much says what i'm asking..

I have been struggling with file upload. What I need to achieve is open a dialog for file upload and save it to database, so nothing too fancy. Basic file upload is more than easy to make. Just form with correct encrypt and input type file. But when I insert my form to dialog something goes wrong and there is nothing in Post. I tried to add test parameters like filename and it worked fine. But the actual file is missing in post.

here's some code:

Form:

@using (Html.BeginForm("Edit", "Home", FormMethod.Post, 
         new { enctype = "multipart/form-data" })){
<label for="Name">Filename: </label>
<input type="text" name="name" id="name"/>  
<input type="file" name="file" id="file" />

<input type="submit"/>
}

Controller:

开发者_Python百科public ActionResult Edit(Attachment model)
    {
        var strLen = Convert.ToInt32(model.file.InputStream.Length);
        var strArr = new byte[strLen];
        model.file.InputStream.Read(strArr, 0, strLen);

        return View();
    }

Edit:

Model:

public class Attachment
{
    public string Name { get; set; }
    public HttpPostedFileBase file{ get; set; }

}

This form is inside the dialog.


Try this,

public ActionResult Edit(HttpPostedFileBase file)
    {
       ////
        return View();
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消