HTTPPostedFileBase always return null in controller

后端 未结 3 1174
礼貌的吻别
礼貌的吻别 2021-01-27 03:03

I have checked various answer for this, but none of them works for me, my code in .cshtml is as follows:


         


        
3条回答
  •  感情败类
    2021-01-27 03:30

    You have to add enctype = "multipart/form-data" in form tag.

    @using (Html.BeginForm("Action", "Controller", FormMethod.Post, 
                                   new { enctype = "multipart/form-data" }))
    

    Try this c# code in controller action

    if (Request.Files != null && Request.Files.Count > 0)
    {
        HttpPostedFileBase file = Request.Files[0];
        if (file != null && file.ContentLength > 0)
        {
        }
    }
    

    You have to retrieve the file.

提交回复
热议问题