2017-07-17 142 views
1

我写在我的项目网站我用的身份,正如你知道“ID”身份使用“GUID”类型,但我有一个问题,当我想获取的“模式弹出”用户的信息,我需要比较“int”值与“GUID”,但我不能这样做。例如:如何比较GUID值int值?

如果(!模型=空& & Model.Id> 0)//我得到了错误( 运算符“>不能被应用到 类型 '字符串' 的操作数)

@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="https://stackoverflow.com/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="https://stackoverflow.com/users/Edit/' + data + '">Edit</a>'; 
        } 
       }, 
       { 
        "data": "UserId", "width": "50px", "render": function (data) { 
         return '<a class="popup" href="https://stackoverflow.com/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> 
+0

将字符串类型转换为int或float和compare。 – guradio

+0

如果您的GUID只是平面号,然后尝试'parseInt函数(yourguid)' –

+0

为什么不把它与比较的String.Empty? – Nico

回答

0

代替

Model.Id > 0 

使用此 - 作为Guid Type列。

Model.Id != Guid.Empty