代码之家  ›  专栏  ›  技术社区  ›  Barbaros Alp

如何在使用MethodForm.Post ASP.NET MVC上载文件时获取表单元素的值?

  •  0
  • Barbaros Alp  · 技术社区  · 15 年前
    <%using (Html.BeginForm("Upload", "Photos", new { id = Model.Gallery.GalleryID }, FormMethod.Post, new { @enctype = "multipart/form-data" }))
              {%>
            <p>
                <span class="bold block">Photo 1:</span>
                <input type="file" name="File1" class="block" />
                <span class="bold block">File Name:</span>
                <input type="text" class="txt-base width50" id="txtFile1" />
                <span class="bold block">Description</span>
                <input type="text" class="txt-base width80" id="txtCaption1" />
    
            </p>            
            <p>
                <input type="submit" class="btn-admin cursorPointer" value="Upload" />
            </p>
            <%}%>
    

    我需要获取txtFile(I)和txtCaption(I)的值。。。

     for (int i = 0; i < Request.Files.Count ; i++)
                {
                    var hpf = Request.Files[i];
                    var strFileName = Request.Form["txtFile" + (i + 1)];
                    var strCaption = Request.Form["txtCaption" + (i + 1)];
                    ...
                    ...
    

    但是由于being方法是“FormMethod.Post”,我无法使用Request.Form[“txtFile1”]获取值;

    1 回复  |  直到 15 年前
        1
  •  1
  •   mtmk    15 年前