C#MVC3 ajax.beginform上传文件不能正常工作 [英] c# MVC3 ajax.beginform to upload file not working

查看:130
本文介绍了C#MVC3 ajax.beginform上传文件不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击提交按钮后。我得到的实体空。
不要任何人有一个解决方案?

查看

  @using(Ajax.BeginForm(CreateRoom,房间,新AjaxOptions {列举HTTPMethod =POST的onComplete =window.location.href =索引} ,新{ENCTYPE =的multipart / form-data的ID =ajaxUploadForm}))
    {
        <输入类型=文件名称=室/>
        <输入类型=提交VALUE =OK/>
    }

控制器

  [HttpPost]
    公众的ActionResult CreateRoom(RoomFileView实体)
    {
        // code
    }

模式

 公共类RoomFileView
    {
        公共RoomFileView();        公众诠释BuildingId {搞定;组; }
        公众诠释CityId {搞定;组; }
        公众诠释CountryId {搞定;组; }
        公众诠释FloorId {搞定;组; }
        公众诠释LocationId {搞定;组; }
        公共HttpPostedFileWrapper室{搞定;组; }        公共字符串的内容();
    }


解决方案

您无法上传使用AJAX的文件。使用notmal Html.BeginForm。请看看这个链接点击这里因为这将是对你有帮助。

如果你想使用异步上传您可以尝试一些可用的上传组件,如Ajax的上传和Uploadify的。

After clicking the submit button. I am getting null in entity. Do anyone have a solution?

View

    @using (Ajax.BeginForm("CreateRoom", "Room", new AjaxOptions { HttpMethod = "POST", OnComplete = "window.location.href='Index'" }, new { enctype = "multipart/form-data", id = "ajaxUploadForm" }))
    {
        <input type="file" name="Room" />
        <input type="submit" value="OK" />
    }

controller

    [HttpPost]
    public ActionResult CreateRoom(RoomFileView entity)
    {
        //code
    }

model

     public class RoomFileView
    {
        public RoomFileView();

        public int BuildingId { get; set; }
        public int CityId { get; set; }
        public int CountryId { get; set; }
        public int FloorId { get; set; }
        public int LocationId { get; set; }
        public HttpPostedFileWrapper Room { get; set; }

        public string Content();
    }

解决方案

You cannot upload files using AJAX. Use the notmal Html.BeginForm. Please Check out this link click here as this will be helpful for you.

If you want to use asynchronous uploads you may try some of the available upload components such as Ajax Upload and Uploadify.

这篇关于C#MVC3 ajax.beginform上传文件不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆