title: Get data using angularjs with restful web api in mvc
body: <p>I need to create an application which gets the data from store procedure and display it on view.</p>
  
  <p>When i was passing id from view to angularjs controller, have the value of that field, but unable to get the same in web api, it displays null(while calling).</p>
  
  <p>To be more specific, have tried various options, some of following:</p>
  
  <ul>
  <li>Used [FromBody]</li>
  <li>Passed string value in json from  angularjs controller to webapi</li>
  </ul>
  
  <p>So, when it is null, it always throws result with fail, not success.</p>
  
  <p>Please help.</p>
  
  <p><strong>Code:</strong></p>
  
  <ul>
  <li>Angularjs (controller)</li>
  </ul>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>app.controller('matchDetailController', function($scope, $http) {
    $scope.getAllMatchDetail = function(matchId) {
      var MatchId = matchId;
      $http.get('/api/[Apicontrollername]/GetAllMatchDetail', MatchId).success(function(data) {
        if (data.status == "success") {
  
        } else {
  
        }
      }).error(function(error) {
        debugger;
      })
    }
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="view_container" id="matchDetail" data-ng-controller="matchDetailController" data-ng-init="getAllMatchDetail(@ViewBag.MatchId)"&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <ul>
  <li><p>webapi</p>
  
  <p>public object GetAllMatchDetail([FromBody]string MatchId)
      {
          SoccerWebviewMatchDetailRepository _SoccerWebviewMatchDetailRepository = new SoccerWebviewMatchDetailRepository();</p>
  
  <pre><code>    List&lt;clsSoccerWebviewMatchDetail&gt; objlstclsSoccerWebviewMatchDetail = _SoccerWebviewMatchDetailRepository.getAllSoccerWebviewMatchDetail(MatchId);
  
      if (objlstclsSoccerWebviewMatchDetail != null &amp;&amp; objlstclsSoccerWebviewMatchDetail.Count() != 0)
      {
          var jsonObject = new
          {
              status = "success",
              objlstclsSoccerWebviewMatchDetail = _SoccerWebviewMatchDetailRepository.getAllSoccerWebviewMatchDetail(MatchId)
          };
  
          return jsonObject;
      }
      else
      {
          var jsonObject = new
          {
              status = "fail",
              message = "No match details found"
          };
  
          return jsonObject;
      }
  }
  </code></pre></li>
  </ul>
  
  <p>Check the code.</p>