How to make a list with ASP.net C # Angular?

0

I'm doing this little example to show what I'm going to enter in the textbox.

the entered object arrives at the controller and returns, when loading it to my table is where it does not come out

view

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <script src="~/Scripts/angular.min.js"></script>
    <script type="text/javascript">
        var app = angular.module('MyApp', [])
        app.controller('MyController', function ($scope, $http, $window) {

            $scope.myData = [];
            $scope.ButtonClick = function () {
                var post = $http({
                    method: "POST",
                    url: "/Home/Angular",
                    dataType: 'json',
                    data: { name: $scope.Name },
                    headers: { "Content-Type": "application/json" }
                }).success(function (result) {
                    $scope.myData = result;
                });
            }
        });
    </script>
    <div ng-app="MyApp" ng-controller="MyController">

        Name: <input type="text" ng-model="Name" />

        <input type="button" value="Submit" ng-click="ButtonClick()" />

        <table>
            <tr class="success">
                <th>Nombre</th>
                <th>Data</th>
            </tr>
            <tr ng-repeat="data in myData">
                <td>{{data.Name}}</td>
                <td>{{data.DateTime}}</td>
            </tr>
        </table>
    </div>
</body>
</html>

control

public class HomeController : Controller
{
    // GET: Home
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public JsonResult Angular(string name)
    {
        PersonModel person = new PersonModel
        {
            Name = name,
            DateTime = DateTime.Now.ToString()
        };
        return Json(person);
    }
}

model

public class PersonModel
{
    ///<summary>
    /// Gets or sets Name.
    ///</summary>
    public string Name { get; set; }

    ///<summary>
    /// Gets or sets DateTime.
    ///</summary>
    public string DateTime { get; set; }
}
    
asked by 14.05.2018 в 18:45
source

0 answers