We help IT Professionals succeed at work.

HTML post to mvc

i have basic HTML form
Included one text box and one box for upload file

Do you have a sample code I can read to
Use JavaScript and Ajax to post both data into Mvc controller in net?

Watch Question




What is wrong with this website?
waiting one reply takes many hours?
And most of them just reply one time and end up nothing
Most Valuable Expert 2017
Distinguished Expert 2019
If you do a search on JavaScript FormData MVC - there are several options that come up including this one


This refers to the FormData solution I posted in your other thread
(From the above post)
var formdata = new FormData($('form').get(0));
  url: '@Url.Action("YourActionName", "YourControllerName")',
  type: 'POST',
  data: formdata,
  processData: false,
  contentType: false,         

Open in new window

More from the same post
and in your controller
public ActionResult YourActionName(YourModelType model)

Open in new window

or (if your model does not include a property for HttpPostedFileBase)
public ActionResult YourActionName(YourModelType model, HttpPostedFileBase myImage)

Open in new window

If you want to add additional information that is not in the form, then you can append it using

formdata.append('someProperty', 'SomeValue');

Open in new window

My advice is do the search - look at some samples, attempt the code above and if you get stuck post back here.