目前,我正在开发 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/