【问题标题】:mvc using angular js when value change in dropdownlist table data changes当下拉列表表数据中的值更改时使用角度 js 的 mvc
【发布时间】:2016-11-04 08:03:20
【问题描述】:

public JsonResult GetdataByID(int Id) { var x = (来自 db.Employees 中的 n 其中 n.Id == Id 选择 n).FirstOrDefault(); 返回新的 JsonResult { 数据 = x,JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }

    public JsonResult GetCountries()
    {
        List<Employee> allCountry = new List<Employee>();
        using (WorkdbEntities dc = new WorkdbEntities())
        {
            allCountry = dc.Employees.OrderBy(a => a.Id).ToList();
        }
        return new JsonResult { Data = allCountry, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
    }

HTML 代码

 <div ng-controller="BindData">
        <select ng-model="Id" ng-options="I.Id as I.Id for I in BindId"  ng-change="GetState()">
        <option value="">Select Id</option>
    </select>

    <table>
        <tr>
            <td>Employeename</td>
        </tr>
        <tr ng-repeat="ff in BindTable">
            <td>
                {{ff.Name}}
            </td>

        </tr>
    </table>

</div>

控制器代码

angular.module("MyApp")

    .controller("BindData", function ($scope, LocationId) {

        $scope.BindId = null;
        $scope.Id = null;
        LocationId.GetCountries()
                    .then(function (d) {
                        $scope.BindId = d.data;})$scope.GetState = function (Employee) {LocationId.GetdataByID($scope.Id).then(function (d) $scope.BindTable = d.data;})}})

工厂代码

.factory("LocationId", function ($http) {

var fac = {};

fac.GetCountries = function () {
    return $http.get("/Home/GetCountries")
}
fac.GetState = function (Id) {
    return $http.get("Home/GetdataByID ? Id=" + Id)
}

return fac;})

【问题讨论】:

    标签: angularjs asp.net-mvc


    【解决方案1】:

    我什至不确定您到底想做什么,但我注意到肯定是错误的一件事是:

    LocationId.GetdataByID()
    

    您从未在 LocationId 对象上定义过 GetdataById 属性/方法。

    请提供更多信息并尝试更清楚地说明您要做什么。

    此外,如果您希望有人帮助您,您确实需要尝试更好地格式化您的问题。阅读代码并不总是那么容易,尤其是当您不努力使其尽可能简单时。

    【讨论】:

    • 我的目标是当 id 更改特定数据获取时,我将 Id 绑定到下拉列表中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    • 1970-01-01
    • 2013-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多