weixin_33733810 2014-09-30 17:31 采纳率: 0%
浏览 41

用mvc5上传图像

i am having trouble uploading an image from the website to the server.

My ajax form is taking everything except the image file. I saw a similar question here ASP.Net MVC 5 image upload to folder

but i can't seem to get it to work

i have this

public HttpPostFileBase imageFile {get;set;}
public string imageText {get;set;}
public string imageTitle {get;set;}
public bool isActive {get;set;}
public DateTime dateAdded {get;set;}
public string urlRedirect {get;set;}

public ActionView Index()
{
   return View;
}

public void UploadImage (CarouselController carouselImage)
{
 // some code
}

my ajax begin form takes in all the fields with html razor.

@Html.TextBoxFor(model =>model.imageText , new {class = "form-control"} )
... similar for the other fields. 
for the image i have 

@html.TextBoxFor(model => model.imageFile), new { type="file"})

this makes it a working selection input box but it doesn't pass any information to the upload method.

see attached picture for what i mean. enter image description here

  • 写回答

3条回答 默认 最新

  • weixin_33670786 2014-09-30 17:42
    关注

    You need to set the following attribute on your form:

    enctype = "multipart/form-data"
    
    评论

报告相同问题?