Asp.net mvc 2 ASP.NET MVC2+;文件上载(HttpPostedFileBase类)
我上传文件有问题。我想从我的编辑视图上传它:Asp.net mvc 2 ASP.NET MVC2+;文件上载(HttpPostedFileBase类),asp.net-mvc-2,file-upload,httppostedfilebase,Asp.net Mvc 2,File Upload,Httppostedfilebase,我上传文件有问题。我想从我的编辑视图上传它: <% using (Html.BeginForm("edit","profile",FormMethod.Post, new { enctype="multipart/form-data" })) {%> <%: Html.ValidationSummary(true) %> <%: ViewData["ErrorMessage"] %> <fieldset
<%
using (Html.BeginForm("edit","profile",FormMethod.Post, new { enctype="multipart/form-data" }))
{%>
<%: Html.ValidationSummary(true) %>
<%: ViewData["ErrorMessage"] %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.Image) %>
</div>
<div class="editor-field">
<input type="file" id="Image" name="Image" />
<label id="LabelErrorImage" class="errorMessage" />
</div>
<p>
<input type="submit" value="Save" onclick="return Validate(); return false;"/>
</p>
</fieldset>
<% } %>
但我总是有空的文件对象,为什么?????你有什么想法,建议,为什么它可以这样工作?我如何将文件值传递给编辑操作可能有问题
编辑: 这真的很奇怪,甚至当我删除
使用(Html.BeginForm(“Index”,“Profile”,FormMethod.Get,new{enctype=“multipart/formdata”}))
页面源仍然具有:
<body>
<form method="post" action="6111e591-b92d-4bcb-b214-ab8f664b35f9" id="form1">
我的意思是我无法更改标签,但不知道为什么://尝试更改:-
public ActionResult Edit(string id, HttpPostedFileBase file,
FormCollection formValues)
致:-
因为您输入的名称是image
<input type="file" id="Image" name="Image" />
编辑
老实说,还有一件事阻止了图像的绑定。这是你贴的全部表格吗
一些需要测试的东西
name=image
的文件
在您的视图中,您将文件输入命名为“image”,但您的操作方法接受一个名为“file”的参数。重命名其中一个,它应该可以工作。此问题的解决方案如下: