【发布时间】:2014-09-30 17:31:16
【问题描述】:
我无法将图像从网站上传到服务器。
我的 ajax 表单正在获取除图像文件之外的所有内容。我在这里看到了类似的问题ASP.Net MVC 5 image upload to folder
但我似乎无法让它工作
我有这个
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
}
我的 ajax begin 表单包含所有带有 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"})
这使它成为一个有效的选择输入框,但它不会将任何信息传递给上传方法。
我的意思见附图。
【问题讨论】:
-
imageFile 是实际文件还是图片所在的位置?
-
我不确定。它是 的等价物,那是图像还是位置?但无论哪种方式,我都认为它没有通过,因为我尝试将 HttpPostFileBase 转换为字符串、对象、HttpPostFile、HttpPostFileBase,并且绝望中我也尝试了一个 byte[]
标签: c# ajax asp.net-mvc razor