您好我是AngularJS的新手,我想在AngularJS的方法中绑定webgrid
$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");
});
}
我想在警告消息之前绑定webgrid。来自服务器的数据采用自定义类
的形式[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;
}
这是我的业务层。
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;
}
}
我使用ajax调用看到很多答案。但我不确定他们是否会奏效。我按照这个答案MVC 3 Razor- how to bind new model to webgrid using jQuery ajax
我能够在angularjs函数The data is in custom class object LogsData中获取数据。如何在mvc webgrid中绑定该数据?
小帮助真的很棒!提前谢谢。
答案 0 :(得分:0)
我使用部分视图解决了我的问题并在其中呈现了webgrid。我在文档加载中调用了局部视图。
<script type="text/javascript">
$(document).ready(function () {
$.get("@Url.Action("RefreshGrid", "Dashboard")", function (data) {
$('#divProduct').replaceWith(data);
});
});
</script>
并使用角度调用按钮单击事件再次渲染局部视图。
答案 1 :(得分:0)
网格渲染应在按钮单击之前进行。如果没有保持序列,则网格不会出现。