c# - asp.net mobile网站添加文件上传控件?

标签 c# asp.net

目前,我正在开发 asp.net 移动网站,我必须在移动网站上实现一项与上传文件相关的功能。

我正在使用 asp:upload 控件,但是它在移动网站上不起作用。

自上周以来,我一直在 google 中搜索此问题,但找不到任何相关来源或博客。

谁能帮我解决这个问题?

最佳答案

在 View 中:

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <input type="file" name="file" />
    <input type="submit" value="OK" />
}

在控制中:

[HttpPost]
        public ActionResult Index(HttpPostedFileBase file)
        {
            // Verify that the user selected a file
            if (file != null && file.ContentLength > 0)
            {
                // extract only the fielname
                var fileName = Path.GetFileName(file.FileName);
                // store the file inside ~/App_Data/uploads folder
                var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                file.SaveAs(path);
            }
            // redirect back to the index action to show the form once again

            return RedirectToAction("Index");
        }

并从您的页面中删除 jquerymobile 脚本。就像在 MVC4 中一样

@Scripts.Render("~/bundles/jquery", "~/bundles/jquerymobile") 

删除这一行,这是冲突的根源。

关于c# - asp.net mobile网站添加文件上传控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8292419/

相关文章:

c# - Parse 诉 TryParse

c# - 通过 GATT (UWP) 向 BLE 设备发送写入请求

c# - 如果禁止跨浏览器请求,如何启用 API 访问?

c# - 如何使用 StreamWriter 创建目录?

c# - 完全禁用 ASP.NET Web 窗体中的 ViewState

c# - Asp.Net 将大量数据从 View 发送到 Controller

c# - 如何根据异常进行有条件的 WaitAndRetry 或 WaitAndRetryForever?

asp.net - 使用 Loggly 时在 log4net 中指定应用程序名称

asp.net - Elmah 的动态电子邮件主题?

C#:当上下文菜单的菜单项链接到两个不同的对象时,如何检测谁是调用者?