html - AngularJs File Upload in asp.net mvc -


here i've tried till now

i cant send file action result, showing me null,

<form ng-show="divpatient" name="patientform" ng-submit="addupdatepatient()">             <table>                 <tr>                     <td>                         <input class="form-control" type="text" readonly placeholder="key (automatic)" ng-model="patientid" />                     </td>                     <td>                         <input id="formfocus" name="firstname" class="form-control" type="text" placeholder="firstname" ng-model="firstname" ng-minlength="3" required />                     </td>                     <td>                         <input name="lastname" class="form-control" type="text" placeholder="lastname" ng-model="lastname" ng-minlength="3" required />                     </td>                     <td>                         <input class="form-control" type="text" placeholder="disease" ng-model="disease" name="disease" ng-minlength="3" required />                     </td>                     <td>                         <input class="form-control" type="number" placeholder="phone no." ng-model="phoneno" name="phoneno" ng-pattern="/^[789]\d{9}$/" required />                     </td>                     <td>                         <input type="file" onchange="angular.element(this).scope().selectfileforupload(this.files)" accept="image/*" class="form-control" ng-model="photourl" value="{{photourl}}" required />                     </td>                     <td colspan="2">                         <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>  $scope.selectfileforupload = function (files) {     $scope.selectedfile = files; }  $scope.addupdatepatient = function () {     var file = $scope.selectedfile[0];     var patient = {         firstname: $scope.firstname,         lastname: $scope.lastname,         disease: $scope.disease,         phoneno: $scope.phoneno     };     var getdata = angularservice.addpatient(patient,filee);     getdata.then(function (msg) {         getallpatients();         alert(msg.data);         $scope.divpatient = false;     }, function () {         alert('error in adding record');     }); } 

here service code

this.addpatient = function (patient, file) {     // showing me file object thats fine     alert("in services" + filee);     // think wrong here shouldn't or can't send file actionresult     var response = $http({         method: "post",         url: "addpatient",         data: json.stringify(patient),         datatype: "json",         // wrong here ??         file : file     });     return response; } 

amd last method in controller

public string addpatient(patient patient,httppostedfilebase file) {          // i'm getting patient data fine, file showing me null } 

is wrong service method ??? or know how send form along files actionresult or method in mvc controller, heard pleople using "new formdata", dont know that, i'm willing learn or use it, if solves problem


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -