0

When I save a file, I would like to return the name of the file to my page and append it to a list. I am not sure how to approach this and am very new with mvc4. Can someone show me how to get the file name from the json after the controller has returned the Content? Thanks!

Line that returns file name: (From the controller) return Content("{\"name\":\"" + r[0].Name + "\"}", "application/json");

Form submission from .cshtml

    @using (Html.BeginForm("SaveDropzoneJsUploadedFiles", "Home", FormMethod.Post, new { enctype = 
    "multipart/form-data" }))
    {
        <input type="file" name="file" multiple/>
        <input type="submit" name="Submit" id="Submit" value="Upload" />
        <div id="fileNames"></div>
    }
jpavlov
  • 2,215
  • 9
  • 43
  • 58
  • Consider it a html/javascript issue, how would your browser handle a submit to an url that returns json? (Hint: It wouldn't. Perhaps rendered pretty by an plugin.) Lookup how to upload files with ajax instead of posting them as a usual page-request (and thus, a page-reload). – sisve Nov 17 '14 at 18:17
  • That was the first thing I tried, except my Request.Files would always come through null when I was debugging in the controller. Do you know of any helpful sites, that might work for me? – jpavlov Nov 17 '14 at 18:22
  • Yes, Stack Overflow have some information that may help. ;) http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery – sisve Nov 17 '14 at 18:24
  • Thanks Simon, not sure how I missed this one. – jpavlov Nov 17 '14 at 18:34

0 Answers0