开发者

MVC2 HttpPostedFileBase object is always nothing

开发者 https://www.devze.com 2023-03-08 06:32 出处:网络
I tried to recreate the thousands of simple examples online, and I Fail everytime. What am I doing wrong?

I tried to recreate the thousands of simple examples online, and I Fail everytime.

What am I doing wrong?

  • Other.aspx

    <%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master"
    

    Inherits="System.Web.Mvc.ViewPage" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent"
    

    runat="server"> Other

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent"
    

    runat="server">

        <h2>Upload A File</h2>
    
         <% Html.BeginForm("UploadFile", "Home")%>
           <input type="file" name="f" />
           <input type="submit" />
           <% Html.EndForm()%>
        </form>
    </asp:Content>
    
    • HomeController.vb

    _ Public Class HomeController Inherits 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 Funct开发者_运维百科ion
    
        <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
    


You need to set the enctype HTML property for the form to multipart/form-data.

0

精彩评论

暂无评论...
验证码 换一张
取 消