File Upload Controls using Razor in ASP.NET MVC3

前端 未结 3 672
故里飘歌
故里飘歌 2021-02-13 05:53

Is there a way to define the file upload controls using a Razor helper in ASP.NET MVC3?

3条回答
  •  抹茶落季
    2021-02-13 06:35

    USING RAZOR

    @*requieres installing Asp helpers / you can do it her from NuGet or logging som admin in packages*@
    @using Microsoft.Web.Helpers;
    @{
        var fileName = "";
        if (IsPost) {
            var fileSavePath = "";
            var uploadedFile = Request.Files[0];
            fileName = Path.GetFileName(uploadedFile.FileName);
            fileSavePath = Server.MapPath("~/UploadedFiles/" +
              fileName);
            uploadedFile.SaveAs(fileSavePath);
        }
    }
    
          @FileUpload.GetHtml(
            initialNumberOfFiles:1,
            allowMoreFilesToBeAdded:false, 
            includeFormTag:false,
            name: "Upload1",
            uploadText:"Upload")
    
        @if (IsPost) {
            File uploaded!
    }

提交回复
热议问题