asp.net-mvc – HttpPostedFileBase总是在ASP.NET MVC中返回null
发布时间:2020-05-23 07:12:10 所属栏目:asp.Net 来源:互联网
导读:我有一个问题,当我上传文件在ASP.NET MVC。 我的代码如下: 视图: @{ ViewBag.Title = Index; Layout = ~/Views/Shared/_Layout.cshtml;}h2Index2/h2@using (Html.BeginForm(FileUpload, Board, FormMethod.Post, n
|
我有一个问题,当我上传文件在ASP.NET MVC。
视图: @{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index2</h2>
@using (Html.BeginForm("FileUpload","Board",FormMethod.Post,new { enctype = "multipart/form-data" }))
{
<input type="file" />
<input type="submit" />
}
控制器: [HttpPost]
public ActionResult FileUpload(HttpPostedFileBase uploadFile)
{
if (uploadFile != null && uploadFile.ContentLength > 0)
{
string filePath = Path.Combine(Server.MapPath("/Temp"),Path.GetFileName(uploadFile.FileName));
uploadFile.SaveAs(filePath);
}
return View();
}
但uploadFile总是返回null。 解决方法@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index2</h2>
@using (Html.BeginForm("FileUpload",new { enctype = "multipart/form-data" }))
{
<input type="file" name="uploadFile"/>
<input type="submit" />
}
您必须提供输入类型文件的名称到uploadfile以便在ASP.net mvc中建模绑定工作,并确保输入类型文件的名称和HttpPostedFileBase的参数名称相同。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – GET与POST真的很重要吗?
- 如何合理地构建我的ASP.NET MVC 2项目与区域
- 了解ASP.Net会话的生命周期
- asp.net-mvc – ASP .Net MVC 3:单元测试控制器动作
- 如何找出重新启动ASP.NET Web应用程序的原因
- asp.net-mvc – 使用linq2sql在c#mvc中不显示所选项的多选列
- asp.net – 保护ELMAH,同时可以通过RSS阅读器访问它
- asp.net-mvc – 可靠地处理ASP.NET MVC模型绑定错误
- asp.net核心 – ASP.NET vNext – 编译代码动态不适合我
- asp.net – DataBinding:’System.Data.DataRowView’不包
推荐文章
站长推荐
- asp.net – 我应该使用哪个PreApplicationStartM
- asp.net – 设置从Codebehind中选择的Radiobutto
- asp.net-mvc – ASP.Net MVC – 视图中的编译器错
- asp.net-mvc – MVC索引页面和过滤器
- asp.net-mvc – OnActionExecuting(FilterExecut
- asp.net – 报表查看器Web控件HTTP处理程序尚未在
- asp.net-ajax – ScriptManager.RegisterClientS
- asp.net – 如何使用Excel服务器端?
- asp.net – 是否有可能欺骗或重用VIEWSTATE或检测
- asp经典 – ASP检查请求方法
热点阅读
