我没有得到正确的输出请解决它也给出了响应,但我没有得到正确的输出。从服务器获取数据并绑定下拉并点击按钮它给出响应这是我的要求我是初学者请尝试解决这个问题
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["Meth"] != null && Request.QueryString["Meth"].ToString() != "")
{
string Req = Request.QueryString["Meth"].ToString();
if (Req == "GL")
{
List<Names> lst = new List<Names>();
lst = GetList();
if (lst != null)
{
string m_Result = JsonConvert.SerializeObject(lst);
Response.Write(m_Result);
}
}
}
}
}
public static List<Names> GetList()
{
List<Names> names = new List<Names>();
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection(@"Data Source=192.168.1.42,1433;Initial Catalog=mycatalog;User ID=myid;Password=mypassword"))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandText = "select RoleName from HN_Master_User_Role";
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(ds);
}
}
}
if (ds != null && ds.Tables.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
names.Add(new Names(dr["RoleName"].ToString()));
}
return names;
}
Angular Code:
var app = angular.module("myApp", []);
app.controller("myCntrl", function ($scope, $http) {
$scope.fillList = function () {
$scope.RoleName = "";
var httpreq = {
method: 'POST',
url: 'WebForm1.aspx?Meth=GL',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'dataType': 'json'
},
data: {}
}
$http(httpreq).success(function (response) {
$scope.RolesList = response;
})
};
$scope.fillList();
$scope.click = function (selectedValue) {
alert(selectedValue);
}
});
HTML代码:
<div ng-app="myApp" ng-controller="myCntrl">
user Roles: <select id="dropdown" name="dropdown" ng-model="dropdown">
<option value="">--Select--</option>
<option data-ng-repeat="Role in RolesList">{{Role.RoleName}}</option>
</select>
</br>
<input id="Button1" type="button" class="button" value="button" ng-click="click(dropdown)" />
</div>
答案 0 :(得分:0)
你不想做一个简单的get
吗?
$http.get("WebForm1.aspx?Meth=GL")
.then(function (response) {
$scope.RolesList = response.data;
});