Can any one tell what is the error???
$scope.country = response;
Here value is coming properly but in dropdown list data is not binding ..it showing undefined....
@{
ViewBag.Title = "Index";
}
Index
//Module
var myApp = angular.module('myApp', []);
//Controller
myApp.controller('MainCtrl', ['$scope', '$http',
function ($scope, $http) {
debugger;
$scope.country = [];
$scope.selectedcountry = null;
$http.get('/Employee/GetCountry').then(function (response) {
$scope.country = response;
});
}]);
============Controller Code=======================
public class Country
{
public int countryId { get; set; }
public string countryName { get; set; }
}
[HttpGet]
public JsonResult GetCountry()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
con.Open();
SqlCommand cmd = new SqlCommand("getAllCountry", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
con.Close();
DataSet ds = new DataSet();
ds.Merge(dt);
List listrs = new List();
foreach (DataRow dr in ds.Tables[0].Rows)
{
listrs.Add(new Country
{
countryId = Convert.ToInt32(dr["countryId"]),
countryName = dr["countryName"].ToString(),
});
}
return Json(listrs, JsonRequestBehavior.AllowGet);
}
==============
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Gokhul VarmanPosted Aug 18, 2017, 12:26 PM