Object Passing from Angular to Controller showing Null Values for Parameters ? MVC

I am trying to pass object from AngularJS 1.x to controller my angular code is like,

 var searchCriteria =
                    from: vm.From,
                    to: vm.To,
                    region: vm.SelectedRegion,
                    city: vm.SelectedCity,
                    buildingType: vm.selectedBuildType,
                    buildingid: vm.selectedHospitalID,
                    leaderId: vm.SelectedTeamLeader,
                    teamid: vm.SelectedTeam,
                    userId: vm.SelectedEvaluator,
                    trainerId: vm.SelectedTrainer,
                    status: vm.selectVisitStatus,

Code to pass above object to controller ,

var controllerUrl = utilitiesService.getFullPath() + '/Survey/establishmentAllRecord/' + { searchCriteria: searchCriteria };

on controller side i am using this code,

public FileResult establishmentAllRecord(object searchCriteria)

On this controller in object searchCreiteria it shows all values null ??

any suggestions ?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

You shold make POST request via, for example, $http service:

.controller('ctrl', ['$http', function($http){
    //your code...

        url: utilitiesService.getFullPath() + '/Survey/establishmentAllRecord',
        method: "POST",
        data: searchCriteria

public FileResult establishmentAllRecord(SearchCriteria searchCriteria)

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply