2017-12-12 1 views
0

서버에서 반환 json 데이터를 가져 오는 중, 모든 값이 상태를 제외한 테이블에 삽입됩니다.ASP.Net MVC에서 버튼 클릭시 활성 또는 비활성?

<script> 
    $(document).ready(function() { 

     $("#DomainID").change(function() { 

      var id = $(this).val(); 
      $("#example tbody tr").remove(); 

      $.ajax({ 

       type: 'POST', 

       url: '@Url.Action("ViewModules")', 
       dataType: 'json', 
       data: { id: id }, 
       success: function (data) { 
        var items = ''; 
        $.each(data.EmpList, function (i, item) { 
         $("#findValue").show(); 

         /*Find Role here - Comparing Emp List ModuleId to RoleList ModuleId*/ 

         var RoleName = $(data.role).filter(function (index, item) { 
          return item.ModuleID == item.ModuleID 
         }); 

         if (item.ParentModuleID == -1) { 

          item.ModuleName = " -- " + item.ModuleName 
         } 
         else { 
          item.ModuleName = item.ModuleName 
         } 

         if (item.Status == "Y") { 
          item.Status = + '<a href="/Account/Enable/' + item.ModuleID + '"><img src="~/img/Active.png" height="32" width="32"/></a>' 
         } 
         else (item.Status == "N") 
         { 
          item.Status = + '<a href="/Account/Enable/' + item.ModuleID + '"><img src="~/img/InActive.png" height="32" width="32"/></a>' 

         } 

         var t = i + 1; 
         var rows = "<tr>" 
         + "<td>" + t + "</td>" 
         + "<td>" + item.ModuleName + "</td>" 
         + "<td>" + item.Url + "</td>" 
         + "<td>" + RoleName[i].RoleName + "</td>" 
         + "<td>" + '<a href="@Url.Action("EditModules", "Account")?id=' + item.ModuleID + '" class="font-icon font-icon-pencil"></a>' + item.Status + "</td>" 
          + "</tr>"; 
         $('#example tbody').append(rows); 
        }); 
       }, 
       error: function (ex) { 
        var r = jQuery.parseJSON(response.responseText); 
        alert("Message: " + r.Message); 
        alert("StackTrace: " + r.StackTrace); 
        alert("ExceptionType: " + r.ExceptionType); 
       } 
      }); 
      return false; 
     }); 
    }); 
</script> 

}

item.Status == "N" 경우는 비활성 이미지를 표시하고 item.Status == "Y" 의미하는 경우 활성 이미지가

하지만 내 코드 상태 값에 내가 어떤 생각을하지 않았다가 표시됩니다 것을 의미합니다.?

컨트롤러 :

public ActionResult ViewModules(int id) 
     { 
      Domain_Bind(); 
      dynamic mymodel = new ExpandoObject(); 
      userType type = new userType(); 


      List<ViewRoleModules> EmpList = type.GetRoleModulesViews(id); 
      List<ViewRoleModules> RoleList; 
      List<ViewRoleModules> role = new List<ViewRoleModules>(); 
      foreach (ViewRoleModules emp in EmpList) 
      { 
       RoleList = type.GetSiteRoleModulesViews(emp.ModuleID); 
       foreach (ViewRoleModules vip in RoleList) 
       { 
        role.Add(new ViewRoleModules 
        { 
         RoleName = vip.RoleName, 
         ModuleID = vip.ModuleID 
        }); 
       } 
      } 

      var data = new { EmpList = EmpList, role = role }; 

      return Json(data, JsonRequestBehavior.AllowGet); 

     } 

table

+0

어디에서 상태를 선언 했습니까? –

+0

'public string Status {get; set;;}'모델에서 –

+0

이미 public string 상태 {get; }이 하나의 @NikhilGhuse –

답변

0

코드는 엉망 약간의 여러 구문 오류 정직하게하는 것입니다. 희망이 도움이 :

 $.ajax({ 
      type: 'POST', 
      url: '@Url.Action("ViewModules")', 
      dataType: 'json', 
      data: { id: id }, 
      success: function (data) { 
       $.each(data.EmpList, function (i, item) { 
        $("#findValue").show(); 
        var roleName = $(data.role).filter(function (index, item) { 
         return item.ModuleID == item.ModuleID 
        }); 

        var moduleName = item.ModuleName; 
        if (item.ParentModuleID == -1) { 
         moduleName = " -- " + moduleName; 
        } 

        var status = ''; 
        if (item.Status == "Y") { 
         status = '<a href="/Account/Enable/' + item.ModuleID + '"><img src="~/img/Active.png" height="32" width="32"/></a>'; 
        } else { 
         status = '<a href="/Account/Enable/' + item.ModuleID + '"><img src="~/img/InActive.png" height="32" width="32"/></a>'; 
        } 

        var row = "<tr>" + 
        "<td>" + (i + 1) + "</td>" + 
        "<td>" + moduleName + "</td>" + 
        "<td>" + item.Url + "</td>" + 
        "<td>" + roleName[i].RoleName + "</td>" + 
        "<td>" + status + "</td>" + 
        "</tr>"; 
        $('#example tbody').append(row); 
       }); 
      }, 
      error: function (ex) { 
       var r = jQuery.parseJSON(response.responseText); 
       alert("Message: " + r.Message); 
       alert("StackTrace: " + r.StackTrace); 
       alert("ExceptionType: " + r.ExceptionType); 
      } 
     }); 
+0

고맙습니다. –

관련 문제