我尝试在线重新创建成千上万的简单示例,每次都失败。
我做错了什么?
Other.aspx
<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master"
Inherits =“System.Web.Mvc.ViewPage”%&gt;
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent"
RUNAT = “服务器” &GT; 其他
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent"
RUNAT = “服务器” &GT;
<h2>Upload A File</h2> <% Html.BeginForm("UploadFile", "Home")%> <input type="file" name="f" /> <input type="submit" /> <% Html.EndForm()%> </form> </asp:Content>
_ 公共类HomeController 继承System.Web.Mvc.Controller
Function Index() As ActionResult ViewData("Message") = "Welcome to ASP.NET MVC!" Return View() End Function Function About() As ActionResult Return View() End Function <HttpPost()> _ Sub UploadFile(f As HttpPostedFileBase) <---Breakpoint here, f is always "Nothing" RedirectToAction("Other") End Sub Function Other() As ActionResult Return View() End Function End Class
答案 0 :(得分:1)
您需要将表单的enctype
HTML属性设置为multipart/form-data
。