We help IT Professionals succeed at work.

HTML post to mvc

ITsolutionWizard
on
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?

Thanks
Comment
Watch Question

Author

Commented:
help?

Author

Commented:
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
Commented:
If you do a search on JavaScript FormData MVC - there are several options that come up including this one

https://stackoverflow.com/questions/29293637/how-to-append-whole-set-of-model-to-formdata-and-obtain-it-in-mvc

This refers to the FormData solution I posted in your other thread
(From the above post)
var formdata = new FormData($('form').get(0));
$.ajax({
  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
[HttpPost]
public ActionResult YourActionName(YourModelType model)
{
}

Open in new window

or (if your model does not include a property for HttpPostedFileBase)
[HttpPost]
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.