javascript - angularJS Form data to ActionResult - ASP .NET MVC -


i want receive formdata parameter in actionresult, don't want covert formdata(), , use request.form in action result, cant receive data directly, without formdata(), here i've tried till ...

<form ng-show="divpatient" name="patientform" ng-submit="addupdatepatient()">             <table>                 <tr>                     <td>                         <input class="form-control" type="text" readonly placeholder="key (automatic)" ng-model="model.patientid" />                     </td>                     <td>                         <input name="firstname" class="form-control" type="text" placeholder="firstname" ng-model="model.firstname" ng-minlength="3" required />                     </td>                     <td>                         <input name="lastname" class="form-control" type="text" placeholder="lastname" ng-model="model.lastname" ng-minlength="3" required />                     </td>                     <td>                         <input class="form-control" type="text" placeholder="disease" ng-model="disease" name="model.disease" ng-minlength="3" required />                     </td>                     <td>                         <input class="form-control" type="number" placeholder="phone no." ng-model="model.phoneno" name="phoneno" ng-pattern="/^[789]\d{9}$/" required />                     </td>                     <td>                         <input type="file" onchange="angular.element(this).scope().selectfileforupload(this.files)" ng-model="model.photourl" value="" class="form-control profilepic" required/>                     </td>                     <td colspan="2" class="savecancel">                         <input type="submit" value="save" class="btn btn-success" ng-disabled="patientform.phoneno.$dirty && patientform.phoneno.$invalid || patientform.lastname.$dirty && patientform.lastname.$invalid || patientform.firstname.$dirty && patientform.firstname.$invalid || patientform.disease.$dirty && patientform.disease.$invalid" />                         <input type="button" value="cancel" class="btn btn-primary" ng-click="cancelform()" />                     </td>                 </tr>                 <tr>                     <td></td>                     <td><span class="eror-text" ng-show="patientform.firstname.$error.minlength">min 3 letters</span></td>                     <td><span class="eror-text" ng-show="patientform.lastname.$error.minlength">min 3 letters</span></td>                     <td><span class="eror-text" ng-show="patientform.disease.$error.minlength">min 3 letters</span></td>                     <td><span class="eror-text" ng-show="patientform.phoneno.$error.pattern">invalid phone no</span></td>                 </tr>             </table>         </form> 

my controller in angularjs

app.controller("studentctrl", function ($scope, angularservice) { $scope.model = {}; $scope.addupdatepatient = function () {     var getdata = angularservice.addpatient($scope.model);     getdata.then(function (msg) {             alert(msg.data);         }, function () {             alert('error in adding record');         });     } } 

my service in angularjs

app.service("angularservice", function ($http) {      // add employee     this.addpatient = function (patientdata) {         var response = $http({             withcredentials: true,             headers: { 'content-type': undefined },             transformrequest: angular.identity,             method: "post",             url: "addpatient",             data: patientdata,             datatype: "json"         });         return response;     } } 

and action result

public string addpatient(patient patientdata) {     //but patientdata fields null } 

my mvc model

using ...  namespace webapplication3.models {     public class patient     {         public int patientid { get; set; }         public string firstname { get; set; }         public string lastname { get; set; }         public long phoneno { get; set; }         public string disease { get; set; }         public string photourl { get; set; }     } } 

i wonder why patientdata in action result null ??

try this

  $http({ method: 'post', url: '/controllername/addpatient', data: patientdata }).                           success(function (data, status, headers, config) {                            }).                           error(function (data, status, headers, config) {                               alert(status);                           }); 

Comments