title: Save image path in database using angularjs
body: <p>I Have uploaded my image in local folder using angular file-model and returning the path using json but i am unable to save the path to database. Please help me to solve this issue. I am using .success method to return the response data to a hidden field to store it in database but it shows ERROR:" Cannot read property 'success' of undefined ".</p>
  
  <p><strong>services.js:</strong></p>
  
  <pre><code>service.UploadFile = function (file) {
      var fd = new FormData();
      fd.append('file', file);
      $http.post('/Empdet/UploadFile', fd, {
          transformRequest: angular.identity,
          headers: { 'Content-Type': undefined }
      })
      .success(function () {
      })
      .error(function () {
      });
  }
  
  return service;
  </code></pre>
  
  <p><strong>Controller.js:</strong></p>
  
  <pre><code> $scope.UploadFile = function () {
      console.log('UploadFile');
      console.log($scope.Empdet.PhotoFile);
      EmployeeFactory.UploadFile($scope.Empdet.PhotoFile).success(function (response) {
          console.log('response.IsSuccessful');
          console.log(response.Data);
  
          $scope.IsSuccessful = response.IsSuccessful;
          if ($scope.IsSuccessful) {
              $scope.PhotoText = response.Data;
              console.log('$scope.PhotoText');
              console.log($scope.PhotoText);                   
              $scope.CanClearMessage = true;
          } else {
              $scope.SuccessMessage = '';
              $scope.ErrorMessage = response.ReasonForFailure;
              $scope.CanClearMessage = true;
          }
      }
  )};
  </code></pre>
  
  <p><strong>CreateNewEmployee.cshtml:</strong></p>
  
  <pre><code> &lt;tr&gt;
      &lt;td style="text-align: left;"&gt;
          &lt;label class="labelsytle"&gt;
              PhotoFile
          &lt;/label&gt;
      &lt;/td&gt;
      &lt;td style="text-align: left;"&gt;
          &lt;input class="form-control" type="file" file-model="Empdet.PhotoFile" style="border-radius: 5px;"/&gt;  
          &lt;td&gt;&lt;button class="btn btn-primary" ng-click="UploadFile()" style="border-radius: 5px; font-family: Consolas;"&gt;UPLOAD&lt;/button&gt;&lt;/td&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      @*&lt;td style="text-align: left;"&gt;
             &lt;label class="labelsytle"&gt;
              PhotoText
          &lt;/label&gt;
      &lt;/td&gt;*@
      &lt;td style="text-align: left;"&gt;
          &lt;input class="form-control" type="hidden" name="search" ng-model="Empdet.PhotoText" placeholder="Enter PhotoText" style="border-radius: 5px;" /&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p><strong>EmpdetController.cs:</strong></p>
  
  <pre><code>[HttpPost]
      public ActionResult UploadFile()
      {
          var file = Request.Files[0];
          var path = Path.Combine(Server.MapPath("~/Photos/") + file.FileName);
          file.SaveAs(path);
  
          // prepare a relative path to be stored in the database and used to display later on.
          path = Url.Content(Path.Combine("~/Photos/" + file.FileName));
          // save to db
          return Json(path.ToString(), JsonRequestBehavior.AllowGet);
  
      }
  </code></pre>