首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Ajax MVC实现图片上传

问使用Ajax MVC实现图片上传
EN

Stack Overflow用户
提问于 2016-12-08 20:39:58
回答 1查看 497关注 0票数 0

我正在尝试使用Ajax.BeginForm上传图像,但在我的控制器中,文件显示为空。我的代码是:

代码语言:javascript
复制
@using (Ajax.BeginForm("Create", "PriceManager", new AjaxOptions
            {
                HttpMethod = "Post",
                InsertionMode = InsertionMode.Replace,
                UpdateTargetId = "PriceList",
                OnSuccess = "ClearInputField",
                OnFailure = "Fail",
                OnComplete = "Complete"


            }, new { enctype= "multipart/form-data" }))

我甚至尝试过使用Html.Begin:

代码语言:javascript
复制
 @{ 
        var attributes = new Dictionary<string, object>();


        attributes.Add("data-ajax-complete ", "Complete");
        attributes.Add("data-ajax-mode", "replace");
        attributes.Add("data-ajax-update ", "#PriceList");
        attributes.Add("id", "form0");
        attributes.Add("enctype", "multipart/form-data");
        attributes.Add("data-ajax", "true");
    }
@using (Html.BeginForm("Create", "ProductManager", FormMethod.Post,attributes))

尽管如此,文件值仍然为空。你知道我做错了什么吗?谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-12-09 15:29:31

试试这个:

代码语言:javascript
复制
    @using (Ajax.BeginForm("About", "Home", new AjaxOptions
{
    HttpMethod = "Post",
    InsertionMode = InsertionMode.Replace,
    UpdateTargetId = "PriceList",
    OnSuccess = "ClearInputField",
    OnFailure = "Fail",
    OnComplete = "Complete"


}, new { enctype = "multipart/form-data" }))
{
    <input type="file" name="flResim" />

    <input type="submit" value="send" />
}

我试过了,也工作了。

​

​

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41039758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档