View & JS:
          @model RCRS.WebApp.LG.Calender.Web.Models.FileModel

          @using (Html.BeginForm("FileUpload", "Home", FormMethod.Post, new { id = "uploadForm", enctype = "multipart/form-data" }))
          {
              @Html.TextBox("data", "", new { type = "file", size = 40, required = "required" })
              @Html.HiddenFor(todocd=>Model.todocd)
              @Html.HiddenFor(todoGroupcd => Model.todoGroupcd)
              <input type="submit" id="submit_upload" value="????????" />
          }

          <div id="todo-file-list">
              @Html.Partial("_todofilelist")
          </div>
           
          <script src="@Url.Content("~/Scripts/jquery.form.js")" type="text/javascript"></script>
          <script type="text/javascript">
              (
          function () {
                  
          var todoList = $('#todo-file-list');
                  
          var filePath = $('input[name="data"]');
                  $('#uploadForm').on('submit', 
          function (e) {
                      e.preventDefault();
                      $(
          this).ajaxSubmit({
                          complete: 
          function (xhr) {
                              filePath.val('');
                              todoList.html(xhr.responseText);
                          }
                      });
                  });
              })();
          </script>

          Controller
                  //-----------------------------------------------------------------------
                  /// <summary>
                  
          /// FileUploadリクエスト時に発生します。
                  
          /// </summary>
                  
          /// <param name="file"></param>
                  
          /// <returns></returns>
                  //-----------------------------------------------------------------------
                  [HttpPost]
                  public ActionResult FileUpload(FileModel file)
                  {
                      int    retValue     = 0;
                      string msg          = string.Empty;
                      string fileName     = string.Empty;
                      int    fileSize     = 0;
                      int    todoGroupcd  = file.todoGroupcd;
                      int    todocd       = file.todocd;
                      string div          = Settings.Default.IsRCRS;
                      DateTime createDate = DateTime.Now;

                      HttpPostedFileBase data = Request.Files["data"];
                      fileName = data.FileName;
                      fileSize = (data.ContentLength / 1000);


                      using (CalenderServiceClient svc = new CalenderServiceClient())     //Calender Serviceを経由
                      {
                          try
                          {
                              retValue = svc.FileUpload(todoGroupcd, todocd, div, fileName, fileSize.ToString(), createDate);       //Uploadファイルをbyte配列に書き込む

                              
          //戻り値でメッセージを分岐
                              if (retValue == 0)
                              {
                                  msg             = CommonFunctions.GetFileName(fileName) + " をアップロードしました。";
                                  ViewBag.Message = msg;
                              }
                              else if (retValue == -1)
                              {
                                  msg             = "ファイルのアップロードに失敗しました。";
                                  ViewBag.Message = msg;
                              }
                          }
                          catch (Exception ex)
                          {
                              Console.WriteLine(ex.Message);
                          }
                          finally
                          {
                              //サービス接続を終了
                              svc.Close();
                          }
                      }

                      TodoModel todoModel = new TodoModel();
                      FileModel files = todoModel.GetBizFile(todocd, todoGroupcd);

                      return Content(CommonFunc.RenderViewToString(ControllerContext, "_todofilelist", files));
                  }
          posted on 2017-02-27 16:50 Ying-er 閱讀(235) 評論(0)  編輯  收藏 所屬分類: .Net
          主站蜘蛛池模板: 三穗县| 子洲县| 漳平市| 定西市| 简阳市| 日照市| 伊金霍洛旗| 溆浦县| 宁陵县| 达孜县| 界首市| 凭祥市| 宣汉县| 民县| 潍坊市| 潮州市| 南京市| 崇礼县| 民丰县| 资兴市| 沂水县| 射洪县| 阜新| 紫金县| 社会| 高台县| 安化县| 天津市| 临沂市| 武乡县| 平果县| 平泉县| 南平市| 江门市| 安岳县| 昭苏县| 宕昌县| 来安县| 民权县| 喜德县| 郁南县|