Hey there, I'm a beginner when it comes to AngularJS and I'm looking to bind the webgrid within the method of AngularJS.
$scope.SaveDetails = function () {
debugger;
var UserID = '@Session["ID"]';
var ID ={ "Application_ID": $scope.Application.ID, "Release_ID": $scope.Release.ID, "Change_ID": $scope.Change.ID, "Environment_ID": $scope.Environment.ID, "Server_ID": $scope.Server.ID, "User_ID": UserID };
if ($scope.Application || $scope.Release || $scope.Change || $scope.Environment || $scope.Server)
$http({
method: 'POST',
url: '/Dashboard/SaveDetails/',
data: { Application_ID: $scope.Application.ID, Release_ID: $scope.Release.ID, Change_ID: $scope.Change.ID, Environment_ID: $scope.Environment.ID, Server_ID: $scope.Server.ID, User_ID: UserID },
}).then(function (resposne) {
debugger;
$scope.grid = resposne.data;
alert("Saved Successfully");
});
}
I'm looking for a way to bind the webgrid before displaying the alert message. The data from the server is returned in a custom class format.
[HttpPost]
public List<LogData> SaveDetails(SelectedID x)
{
application.SaveLogs(x.Application_ID, x.Release_ID, x.Change_ID, x.Environment_ID, x.Server_ID, x.User_ID);
BLLogTable logs = new BLLogTable();
List<LogData> data = new List<LogData>();
data = logs.GetData(10, 10);
return data;
}
This section showcases my Business Layer.
public class BLLogTable
{
BRMContext db = new BRMContext();
public List<LogData> GetData(int rowCount, int rowFrom)
{
var param1 = new SqlParameter();
param1.ParameterName = "@Value1";
param1.SqlDbType = SqlDbType.Int;
param1.SqlValue = rowCount;
var param2 = new SqlParameter();
param2.ParameterName = "@Value2";
param2.SqlDbType = SqlDbType.Int;
param2.SqlValue = rowFrom;
var query = db.LogDataContext.SqlQuery("BRM.spLogs @value1,@value2", param1, param2).ToList();
List<LogData> x = new List<LogData>();
foreach (var log in query)
x.Add(log);
return x;
}
}
I've come across several solutions involving AJAX calls, but I wasn't confident they would work. Instead, I followed this answer on how to bind a new model to a webgrid using jQuery AJAX
I've managed to retrieve the data in my AngularJS function The data is stored in a custom class object named LogsData. How can I go about binding this data in an MVC webgrid?
A little assistance would be greatly appreciated! Thank you in advance.