locked
Passing Value to a Angular Controller from MVC Controller Action RRS feed

  • Question

  • User482643855 posted

    Hi ,

    I have a Angular MVC Application my Angular controller code is like below.

    app.controller('SearchController', ['$scope','$http',function ($scope, $http) {
        $scope.sessionGuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
        $scope.searchValue = "";
        $scope.stockNumber = "";

        $scope.searchRequest = {
            Criteria: [],
            resultsTabIndex: 0,
            orderBy: "sortbypopularity",
            value:"mut" //Added
         
        };

    I have a view Search.Html Which display the data on the basis of searchRequest object which is defined in Controller above.

    Now i have a requirement that i Need to show this view from MVC controller.

    Do you have any idea how can i pass value to controller which is required by the search request object  so that i can show the view with the data.

    Thanks

    Thursday, January 15, 2015 9:53 AM

Answers

  • User1918509225 posted

    Hi Shailendra,

    For your issue  is more related with Angular which is out of our support scope, I suggest that you could post their forum for a professional solution:

    https://groups.google.com/forum/#!forum/angular

    Best  Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 20, 2015 2:41 AM

All replies

  • User1918509225 posted

    Hi Shalendra,

    You could try to use $.http to fire a request  to MVC Controller in your Angularjs Controller.

    Please refer to the code snippet refer to  the link:

    var indexController=function($scope,$http){
    
          var resultPromise=$http.get("/Home/GetTweets");
    
          resultPromise.success(function(data){
    
             $.scope.tweets=data;
    
      });
    
    }
    

    In addition,I suggest that you could refer to the tutorial regarding  Angularjs with Asp.net MVC:

    http://www.codeproject.com/Articles/806029/Getting-started-with-AngularJS-and-ASP-NET-MVC-Par

     

    Best Regards,

    Kevin Shen.

     

    Thursday, January 15, 2015 9:55 PM
  • User482643855 posted

    HI Kevin,

    I am using using http service in my code and getting the data through my web api.

    but I want to initialize my angular view with some initial data/parameter which i can use in my angular controller.

    Thanks

    Monday, January 19, 2015 9:33 AM
  • User1918509225 posted

    Hi Shailendra,

    For your issue  is more related with Angular which is out of our support scope, I suggest that you could post their forum for a professional solution:

    https://groups.google.com/forum/#!forum/angular

    Best  Regards,

    Kevin Shen.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 20, 2015 2:41 AM