0

I've trying to send a file through Ajax.beginForm with enctype = "multipart/form-data", but I always get it as null,

I'm returning a JavaScriptResult from My controller like this,

public JavaScriptResult SaveFile(MyModel model)
{
    JavaScriptResult result = new JavaScriptResult();
    result.Script = "$('#ShowPopup').trigger('click')";

    return result;
}

When using Html.BeginForm it works great, but when it returns the result, it shows the following on the browser,

I don't know what's wrong with Html.BeginForm(), also when I'm returning a view, the view returns but without the my _Layout.cshtml page, breaks my design,

so the problem is when I use ajax it perfectly great but doesn't post file, and when I'm using html.beginForm, it posts the file, but breaks the design after return.

4
  • you want to upload a file through ajax? Commented Apr 15, 2015 at 6:31
  • What properties does your MyModel contains?? Commented Apr 15, 2015 at 6:32
  • 3
    If you want to post using ajax, you need to use FormData as shown in this example. And then you can just call "$('#ShowPopup').trigger('click')"; in the success callback rather than trying to return a script. Commented Apr 15, 2015 at 6:33
  • You can use an Html.BeginForm and in java script convert it to ajax request in javascript using jquery form plugin. I use it and it works great. Please look at the questions here and here Commented Apr 15, 2015 at 6:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.