I have a html form defined as:
<form id="userForm" name="userForm" class="form-horizontal" role="form" ng-submit="submitForm()" novalidate>
with a few input fields tied to an ng-model as so:
<input type="text" class="form-control" ng-model="formAttributes.title" name="formTitle" placeholder="Title of the Form" required>
I then post the form object via an angular service to a .net WebAPI 2 controller using:
$http.post('/api/UI', "=" + JSON.stringify(userForm))
The Post method in WebAPI2 takes [FromBody]string value and I got this type of post to work when userForm was a scope JSON object INSTEAD of the html form object itself but for whatever reason it doesn't work if I'm passing the html form object.
I have a ton of forms that I'm going to need to post to similar controllers, is there relatively easy way to post an html form object to a webapi2 controller without having to manipulate the form data object itself? Or, more clearly, is there a way to prepare webapi2 post method so that I can call it like this:
$http.post('/api/UI',userForm)
I've read a ton of articles on webapi2 and that got me to successfully submit an arbitrary $scope.object that I created using the method above (if I prepend it with an "=", stringify the json object, and changed the contenttype header to json/charset8) but being able to submit the form itself seems a lot cleaner and I would prefer to do things that way. In any case I would like to know why I can't submit the html form object after I stringify it anyway.
Any help would be greatly appreciated. Thanks in advance!