Angularjs with Guid in Asp.NET MVC

Asked

Viewed 107 times

0

I am using Angularjs for the first time and I would like to know why this is not possible, I notice that during the debug, there are several errors of Parse inside the angular min.js, I believe it is because the type that I am passing to his controller is of the type Guid. Some solution?

<script>
    angular.module("tecboxAngular").controller("SetorController",
        function ($scope) {
            $scope.SetarIdParaEdicao = function (itemId) {
                alert(itemId);
                $scope.setorId = itemId;              // The function returns the product of p1 and p2
            }
        });
</script>

@using (Html.BeginForm())
{
    <div class="table-responsive" ng-model="setorId" ng-controller="SetorController">
        <table class="table table-hover" style="font-size: 11px; font-weight: 500;">
            <thead>
                <tr>
                    <th>NOME</th>
                </tr>
            </thead>
            <tbody>
                @{
    int classAux = 0;
    string classe;

    foreach (var item in Model)
    {
        if (classAux > 0)
        {
            classe = "warning";
            classAux = 0;
        }
        else
        {
            classe = String.Empty;
            classAux++;
        }
        <tr class="@classe" ng-click="SetarIdParaEdicao(@item.Id)">
            <td>
                @Html.DisplayFor(x => item.Nome)
            </td>
        </tr>
    }
                }
            </tbody>
        </table>
        <a class="btn btn-primary" href="/Setor/Edit/{{setorId}}">Editar</a>
    </div>
}

the tags that boot Angularjs are in another file, but everything is working, because Alert inside the script works when I change the value that is passed by the controller.

1 answer

0

Declaration by the div

<div class="table-responsive" ng-model="setorId" ng-controller="SetorController">

Call the controller setting the variable with the id of the current item.

<tr class="@classe" ng-click="SetarIdParaEdicao('@item.Id')">
    <td>
        @Html.HiddenFor(x => item.Id)
        @Html.DisplayFor(x => item.Nome)
    </td>
</tr>

Controller

<script>
    angular.module("tecboxAngular").controller("SetorController", function ($scope) {
        $scope.GetIdParaEdicao = function (itemId) {
            $scope.setorId = itemId;
        }
    });
</script>
  • Luiz, if your answer answered your question, you can mark it as reply. This helps others identify that this question has already been answered.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.