gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:24 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com