locked
return json object after form submitted completed RRS feed

  • Question

  • User-1952516322 posted

    Hi,

    I want to return Json object after form submit.

    If I have below case:

    @using (Html.BeginForm("Upload","Home",FormMethod.Post,new{id = "myForm", enctype = "multipart/form-data"}))
    {
    <input type="file" name="files" /> <input type="submit" /> } public ActionResult Upload(IEnumerable<HttpPostedFileBase> files){ return Json(new { result = "success", errors = "Fail" }, JsonRequestBehavior.AllowGet); } // How can I read this object in View again or pass this json object as parameter to javascript function, Note: I did not call the action "Upload" by ajax. ex:
    $.ajax({ url: 'Url.Action("Upload","Home"), data:... etc success:function(data){ // If I do this way, I can read object. But I want to call function after submit completed. // I tried attributes > onsubmit / AjaxOptions OnComplete ... but nothing work. } }); Any assist please.

    Saturday, October 12, 2019 1:36 AM

Answers

  • User475983607 posted

    How can I read this object in View again or pass this json object as parameter to javascript function, Note: I did not call the action "Upload" by ajax. e

    Your current approach replaces the HTML form and AJAX function with JSON within the browser window.  Use AJAX to upload the file(s) and handle the response.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 12, 2019 11:42 AM