2014-02-12 2 views
-1

Привет, я недавно начал работать над MVC4 с Razor View Engine, я использую Entity Framework 5 для доступа к данным My Data, мне нужно отображать информацию пользователя в пользовательском интерфейсе, поэтому я реализовал Flexigrid с помощь статьи Codeproject, но это не работает для меня. Когда я запускаю свое приложение, ничего не отображается, кроме простой старой встроенной индексной страницы. Я пытаюсь реализовать только страницу Flexigrid на странице Index. My View Code Похож {Flexigrid не работает с MVC4 Razor с EntityFramework

<table id="notification" style="display:none"> 
    <script type="text/javascript"> 
     $("#notifications").flexigrid({ 
      url: 'Controllers/Notifications/NotificationsList', 
      dataType: 'json', 
      colModel: [ 
       { display: 'NotificationID', name: 'NotificationID', width: 40, sortable: true, align: 'left' }, 
       { display: 'Notification', name: 'Notification', width: 100, sortable: true, align: 'left' }, 
       { display: 'IsDisplay', name: 'IsDisplay', width: 100, sortable: true, align: 'left' }, 
       { display: 'CreatedBy', name: 'CreatedBy', width: 100, sortable: true, align: 'left' }, 
       { display: 'CreatedOn', name: 'CreatedOn', width: 100, sortable: true, align: 'left' }, 
       { display: 'ModifiedBy', name: 'ModifiedBy', width: 80, sortable: true, align: 'left' }, 
       { display: 'ModifiedOn', name: 'ModifiedOn', width: 60, sortable: true, align: 'left' } 

       ], 
      searchitems: [ 
       { display: 'NotificationID', name: 'NotificationID' }, 
       { display: 'Notification', name: 'Notification' }, 
       { display: 'IsDisplay', name: 'IsDisplay' }, 
       { display: 'CreatedBy', name: 'CreatedBy' }, 
       { display: 'CreatedOn', name: 'CreatedOn' }, 
       { display: 'ModifiedBy', name: 'ModifiedBy' } 
       ], 
      sortname: 'NotificationId', 
      sortorder: 'asc', 
      usepager: true, 
      title: 'Notifications', 
      useRp: true, 
      rp: 15, 
      showTableToggleBtn: true, 
      width: 1040, 
      height: 380 
     }); 
    </script> 
    </table> 
} 

Controller Look Like {

public ActionResult NotificationsList() 
     { 

      var q = from c in db.Tbl_Notification 
        select c; 

      List<Tbl_Notification> notes = q.ToList(); 
      FlexigridObject flexigridObject = new FlexigridObject(); 
      flexigridObject.page = 1; 
      flexigridObject.total = db.Tbl_Notification.Count(); 
      foreach (Tbl_Notification notify in notes) 
      { 
       FlexigridRow cell = new FlexigridRow() 
       { 
        id = notify.NotificationId, 
        cell = GetPropertyList(notify) 
       }; 
       flexigridObject.rows.Add(cell); 
      } 

      return View("FlexigridObject", flexigridObject); 
     } 

     private List<string> GetPropertyList(object obj) 
     { 
      List<string> propertyList = new List<string>(); 

      Type type = obj.GetType(); 
      PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); 
      foreach (PropertyInfo property in properties) 
      { 
       object o = property.GetValue(obj, null); 
       propertyList.Add(o == null ? "" : o.ToString()); 
      } 

      return propertyList; 
     } 
    } 
    public static class ExtensionMethods 
    { 
     public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string propertyName, bool asc) 
     { 
     var type = typeof(T); 
     string methodName = asc ? "OrderBy" : "OrderByDescending"; 
     var property = type.GetProperty(propertyName); 
     var parameter = Expression.Parameter(type, "p"); 
     var propertyAccess = Expression.MakeMemberAccess(parameter, property); 
     var orderByExp = Expression.Lambda(propertyAccess, parameter); 
     MethodCallExpression resultExp = Expression.Call(typeof(Queryable), methodName, new Type[] { type, property.PropertyType }, source.Expression, Expression.Quote(orderByExp)); 
     return source.Provider.CreateQuery<T>(resultExp); 
    } 

    public static IQueryable<T> Like<T>(this IQueryable<T> source, string propertyName, string keyword) 
    { 
     var type = typeof(T); 
     var property = type.GetProperty(propertyName); 
     var parameter = Expression.Parameter(type, "p"); 
     var propertyAccess = Expression.MakeMemberAccess(parameter, property); 
     var constant = Expression.Constant("%" + keyword + "%"); 
     MethodCallExpression methodExp = Expression.Call(null, typeof(SqlMethods).GetMethod("Like", new Type[] { typeof(string), typeof(string) }), propertyAccess, constant); 
     Expression<Func<T, bool>> lambda = Expression.Lambda<Func<T, bool>>(methodExp, parameter); 
     return source.Where(lambda); 
    } 
} 

}

Мне нужно implememnt Сетку любой ценой, пожалуйста, предложите мне. и, пожалуйста, дайте мне знать, что пользовательский интерфейс Kendo можно использовать бесплатно.

ответ

0

Похоже, что вы, возможно, пропустили добавление вызова функции $(document).ready() вокруг скрипта flexigrid. Таким образом, браузер вообще не ссылается на ваш flexigrid.

Попробуйте это:

<table id="notification" style="display:none"> 
    <script type="text/javascript"> 
$(document).ready(function() { 
     $("#notifications").flexigrid({ 
      url: 'Controllers/Notifications/NotificationsList', 
      dataType: 'json', 
      colModel: [ 
       { display: 'NotificationID', name: 'NotificationID', width: 40, sortable: true, align: 'left' }, 
       { display: 'Notification', name: 'Notification', width: 100, sortable: true, align: 'left' }, 
       { display: 'IsDisplay', name: 'IsDisplay', width: 100, sortable: true, align: 'left' }, 
       { display: 'CreatedBy', name: 'CreatedBy', width: 100, sortable: true, align: 'left' }, 
       { display: 'CreatedOn', name: 'CreatedOn', width: 100, sortable: true, align: 'left' }, 
       { display: 'ModifiedBy', name: 'ModifiedBy', width: 80, sortable: true, align: 'left' }, 
       { display: 'ModifiedOn', name: 'ModifiedOn', width: 60, sortable: true, align: 'left' } 

       ], 
      searchitems: [ 
       { display: 'NotificationID', name: 'NotificationID' }, 
       { display: 'Notification', name: 'Notification' }, 
       { display: 'IsDisplay', name: 'IsDisplay' }, 
       { display: 'CreatedBy', name: 'CreatedBy' }, 
       { display: 'CreatedOn', name: 'CreatedOn' }, 
       { display: 'ModifiedBy', name: 'ModifiedBy' } 
       ], 
      sortname: 'NotificationId', 
      sortorder: 'asc', 
      usepager: true, 
      title: 'Notifications', 
      useRp: true, 
      rp: 15, 
      showTableToggleBtn: true, 
      width: 1040, 
      height: 380 
     }); 
     }); 
    </script> 
    </table> 

Кроме того, это может быть не самая лучшая идея, чтобы иметь сценарий находиться внутри макета таблицы. Делает суп-тег.

Смежные вопросы