如何将int值与GUID值进行比较?

时间:2017-07-17 04:59:12

标签: jquery asp.net-mvc guid

我正在我的项目中编写一个网站我使用了身份,因为您知道身份使用“GUID”类型为“id”,但是当我想在“模态弹出窗口”中获取用户信息时我有一个问题我需要将“int”值与“GUID”进行比较但我不能这样做。例如:

  

if(Model!= null&& Model.Id> 0)//我收到了错误(   运营商'>'不能应用于'string'类型的操作数   )

    @model  DataLayer.User

@using (Html.BeginForm("Edit", "users", FormMethod.Post, new { id = "popupForm" }))
{
    if (Model != null && Model.Id > 0)
    {
        @Html.HiddenFor(a => a.Id)
    }
    <div class="form-group">
        <label>User Name</label>
        @Html.TextBoxFor(a => a.UserName, new { @class = "form-control" })
        @Html.ValidationMessageFor(a => a.UserName)
    </div>
    <div class="form-group">
        <label>First Name</label>
        @Html.TextBoxFor(a => a.FirstName, new { @class = "form-control" })
        @Html.ValidationMessageFor(a => a.FirstName)
    </div>

    <div class="form-group">
        <label>Last Name</label>
        @Html.TextBoxFor(a => a.LastName, new { @class = "form-control" })
        @Html.ValidationMessageFor(a => a.LastName)
    </div>
    <div class="form-group">
        <label>Gender</label>
        @Html.TextBoxFor(a => a.Gender, new { @class = "form-control" })
        @Html.ValidationMessageFor(a => a.Gender)
    </div>
    <div class="form-group">
        <label>Condition</label>
        @Html.TextBoxFor(a => a.IsActive, new { @class = "form-control" })
        @Html.ValidationMessageFor(a => a.IsActive)
    </div>

    <div class="form-group">
        <label>Email</label>
        @Html.TextBoxFor(a => a.Email, new { @class = "form-control" })
        @Html.ValidationMessageFor(a => a.Email)
    </div>
    <div class="form-group">
        <label>Address</label>
        @Html.TextBoxFor(a => a.Address, new { @class = "form-control" })
        @Html.ValidationMessageFor(a => a.Address)
    </div>
    <div class="form-group">
        <label>PhoneNumber</label>
        @Html.TextBoxFor(a => a.PhoneNumber, new { @class = "form-control" })
        @Html.ValidationMessageFor(a => a.PhoneNumber)
    </div>

    <div>
        <input type="submit" value="Edite" />
    </div>
}

=======================================

    @*@using DataLayer
    @model IEnumerable<DataLayer.User>*@
@model  IEnumerable<Dentistry.Areas.ViewModels.UserViewModel>


@{
    ViewBag.Title = "مدیریت کاربران";
}

@*<h2>مدیریت کاربران</h2>*@

<head>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css" />
</head>


<div class="row">
    <div class="col-md-6">
        @*<a type="button" class="btn  btn-success btn-flat btn-md" href="@Url.Action("Create","Users")"><span class="fa fa-plus"></span>  افزودن کاربر جدید </a>*@
        <a type="button" class="btn  btn-success btn-flat btn-md" href="/users/create/0"><span class="fa fa-plus"></span>  افزودن کاربر جدید </a>
    </div>
</div>
<br />

<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">کاربران</h3>
                <div class="box-tools">
                    <div class="input-group input-group-sm" style="width: 150px;">
                        <input type="text" name="table_search" class="form-control pull-right" placeholder="Search">
                        <div class="input-group-btn">
                            <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding tablecontainer">

                <table class="table direction table-hover" id="myDatatable">
                    <thead>
                        <tr>
                            <th>UserName </th>
                            <th>FirstName </th>
                            <th>LastName</th>
                            <th>Gender</th>
                            <th>Email</th>
                            <th>Condition</th>
                            <th>Address</th>
                            <th>phonenumber</th>
                        </tr>
                    </thead>


                </table>
            </div>
            <!-- /.box-body -->
        </div>
        <!-- /.box -->
    </div>
</div>

<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
                <h4 class="modal-title custom_align" id="Heading">ویرایش کاربران</h4>

                <div class="modal-body" id="editBody">


                </div>
            </div>

            <div class="modal-footer ">
                <a class="btn btn-warning btn-flat btn-lg" style="width: 100%;"><span class="glyphicon glyphicon-ok-sign"></span> ویرایش کاربر</a>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>



<!-- Modal -->
<div class="modal fade" id="delete" tabindex="-1" role="dialog" aria-labelledby="delete" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
            </div>
            <div class="modal-body">
                ...
            </div>
            <div class="modal-footer ">
                <button type="button" class="btn btn-success"><span class="glyphicon glyphicon-ok-sign"></span> Yes</button>
                <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> No</button>
            </div>
        </div>
    </div>
</div>

<script src="~/Scripts/jquery-3.1.1.min.js"></script>
<script src="~/scripts/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.6/jquery.validate.unobtrusive.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script>
    $(document).ready(function () {

        var oTable = $("#myDatatable").DataTable({
            "ajax":
            {
                "url": '/users/Index',
                "type": "get",
                "datatype": "json"
            },
            "Columns": [
                { "data": "UserName", "autoWidth": true },
                { "data": "FirstName", "autoWidth": true },
                { "data": "LastName", "autoWidth": true },
                { "data": "Gender", "autoWidth": true },
                { "data": "Email", "autoWidth": true },
                { "data": "Condition", "autoWidth": true },
                { "data": "PhoneNumber", "autoWidth": true },
                { "data": "Address", "autoWidth": true },
                {
                    "data": "UserId", "width": "50px", "render": function (data) {
                        return '<a class="popup" href="/users/Edit/' + data + '">Edit</a>';
                    }
                },
                {
                    "data": "UserId", "width": "50px", "render": function (data) {
                        return '<a class="popup" href="/users/delete/' + data + '">Delete</a>';
                    }
                }
            ]
        })
        $('.tablecontainer').on('click', 'a.popup', function (e) {
            e.preventDefault();
            OpenPopup($(this).attr('href'));
        });

        function OpenPopup(pageUrl) {
            var $pageContent = $('<div/>');
            $pageContent.load(pageUrl, function () {

                $('#popupForm', $pageContent).removeData('validator');
                $('#popupForm', $pageContent).removeData('unobtrusiveValidation');
                $.validator.unobtrusive.parse('form');

            });

            $dialog = $('<div class="popupWindow" style="overflow:auto"></div>')
                .html($pageContent)
                .dialog({
                    draggable: false,
                    autoOpen: false,
                    resizable: false,
                    model: true,
                    title: 'Popup Dialog',
                    height: 550,
                    width: 600,
                    close: function () {
                        $dialog.dialog('destroy').remove();
                    }
                })

            $('.popupWindow').on('submit', '#popupForm', function (e) {
                var url = $('#popupForm')[0].action;
                $.ajax({
                    type: "POST",
                    url: url,
                    data: $('#popupForm').serialize(),
                    success: function (data) {
                        if (data.status) {
                            $dialog.dialog('close');
                            oTable.ajax.reload();
                        }
                    }
                })

                e.preventDefault();
            })

            $dialog.dialog('open');

        }

        //var EditUser = function (userId) {
        //    var url = "/Users/Edit?userId=" + userId;
        //    $("#editBody").load(url, function () {
        //        $("#edit").modal("show");
        //    });
        //}


        //$("#mytable #checkall").click(function () {
        //    if ($("#mytable #checkall").is(':checked')) {
        //        $("#mytable input[type=checkbox]").each(function () {
        //            $(this).prop("checked", true);
        //        });

        //    } else {
        //        $("#mytable input[type=checkbox]").each(function () {
        //            $(this).prop("checked", false);
        //        });
        //    }
    });





    //});


</script>

1 个答案:

答案 0 :(得分:0)

而不是

Model.Id > 0

使用它 - 因为它是Guid Type列。

Model.Id != Guid.Empty