Not able to upload file using Ajax.BeginForm() asynchronously

后端 未结 4 1698
故里飘歌
故里飘歌 2020-12-01 21:56

I\'m trying to upload a file using Ajax.BeginForm(), but it\'s not working out.

My view contains:

@using (Ajax.BeginForm(\"UploadFile\", null, new Aj         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-01 22:07

    very simple solution:

      @using (Ajax.BeginForm("action", "controller", new AjaxOptions
            {
                HttpMethod = "post",
                InsertionMode = InsertionMode.Replace,
                OnBegin = "startLoader",
                OnSuccess = "Update_Record",
                UpdateTargetId = "Succ_Msg"
            },new { enctype = "multipart/form-data" }))
    

    notice the new { enctype = "multipart/form-data" } which tells the razor page to add the enctype that can pass HttpPostedFileBase

    good luck:).

提交回复
热议问题