$scope.getSearchResults = function (model) {
        $http({
            method: 'POST',
            url: $scope.getUrl('mySearchUrl'),
            data: { model: $scope.model }
        }).then(function successCallBack(response) {

            $scope.model = response.data;

        }, function errorCallback(response) {
            alert("There was an error gathering the entity information. 
Please try again");
        });
    };

The "model" is a C# view model class. I'm using "POST" so I can send the 
whole object as a param. I have 3 input params that should keep their 
values after the $http call, but they're blank when the results come in. 
I'm simply assigning "response.data" to my $scope.model variable when the 
call completes, so I'd think my input fields (which are still set with the 
correct values) would persist after performing my query. If I do a 
console.log in the "successCallback" function, all the input values as well 
as the search results are included. I'm not sure why my input fields are 
blank when the query finishes. 

This is my controller code:

[HttpPost]
public virtual JsonResult GetSearchResults(SearchViewModel model)
{
    model.SearchResults = 
_itemManager.GetMaterialHistory(model.EntityNumber.ToUpper(),
                                                          
model.StartDate.Value,
                                                          
model.EndDate.Value);

    return Json(model);
}

Except for the input fields winding up blank, this works exactly as I want 
it. When creating a query page, I usually like to create a C# view model 
that contains properties for the search parameters, the results, and 
possibly some state information I might need on the page. I was tasked with 
converting my Razor view syntax to AngularJS. It was a little different in 
initializing DataTables, but wasn't too difficult. The only answers I've 
seen online for keeping input parameters after the query suggested using 
cookies or ng-storage, which seems like a clunky solution. Can anyone 
explain why the model I pass back to the page contains the search params, 
but the input fields are left blank?



-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/angular/220ef425-13e9-46d7-b3e8-26c4e167d563%40googlegroups.com.

Reply via email to