Re: Can ajax upload file to a controller instead of uploadHanler.ashx?

  •  11-20-2012, 10:31 PM

    Re: Can ajax upload file to a controller instead of uploadHanler.ashx?

    Hi. Terry.

    It works, thank you for your quick support. But I like to do little further. In the controller I got an action.

     

    [HttpPost]

    public ActionResult UploadHandler(string description)

    {

          CuteWebUI.MvcUploader uploader = new CuteWebUI.MvcUploader(System.Web.HttpContext.Current);

          uploader.AllowedFileExtensions = "*.png,*.jpg,*.rar";

          uploader.TempDirectory = "~/App_Data";

                uploader.MaxSizeKB = 200;

          uploader.PreProcessRequest();

    if (uploader.IsValidationRequest)

    {

          CuteWebUI.MvcUploadFile file = uploader.GetValidatingFile();

          if (file.FileSize < 100000)

          {

          uploader.WriteValidationError("File is too small");

          }

    else

    {

          uploader.WriteValidationOK("OK");

          }

          Response.End();

          }

          return View();

    }

    and I view I write

     

    @{Html.BeginForm();}

    @Html.Raw(ViewBag.uploaderhtml)

    <input type="text" name="description" value=" " />

    <br />

    <br />

    <button id="SubmitButton" onclick="return submitbutton_click()">Submit</button>

    @{Html.EndForm();}

    <script type="text/javascript">

    function submitbutton_click() {

    var submitbutton = document.getElementById('SubmitButton');

    var uploadobj = document.getElementById('myuploader');

    if (!window.filesuploaded) {

    if (uploadobj.getqueuecount() > 0) {

    uploadobj.startupload();

    }

    else {

    var uploadedcount = parseInt(submitbutton.getAttribute("itemcount")) || 0;

    if (uploadedcount > 0) {

    return true;

    }

    alert("Please browse files for upload");

    }

    return false;

    }

    window.filesuploaded = false;

    return true;

    }

    function CuteWebUI_AjaxUploader_OnPostback() {

    window.filesuploaded = true;

    var submitbutton = document.getElementById('SubmitButton');

    submitbutton.click();

    return false;

    }

    </script>

     

    My point here is to get a fille and a description for it in the handler.  I had license about a year ago with username  [email protected]

    But just got this problem recently.

     

View Complete Thread