In my previous asp.net mvc web projects, I use to manually do column sorting, filtering , search , etc.
But now I read about available web grids plugins, such as jqGrid, jtable, etc. as it can save me a lot of time to deliver sort, filter, paging features. But I have a couple of questions about using these web grids inside asp.net mvc views, as it seems that I will lose important asp.net mvc features when using these web grids.
- For example when building the jqgrid, i will be writing something such as the following inside my razor view:-
<script type="text/javascript"> jQuery("#jQGridDemo").jqGrid({ url: '', datatype: "json", colNames: ['Id','First Name', 'Last Name', 'Last 4 SSN', 'Department', 'Age', 'Salary', "Address",'Marital Status'], colModel: [ { name: '_id', index: '_id', width: 20, stype: 'text' }, { name: 'FirstName', index: 'FirstName', width: 150 }, { name: 'LastName', index: 'LastName', width: 150 }, { name: 'LastSSN', index: 'LastSSN', width: 100 }, { name: 'Department', index: 'Department', width: 80, align: "right" }, { name: 'Age', index: 'Salary', width: 80, align: "right" }, { name: 'Salary', index: 'Salary', width: 80, align: "right" }, { name: 'Address', index: 'Address', width: 150, sortable: false }, { name: 'MaritalStatus', index: 'MaritalStatus', width: 100, sortable: false } ], rowNum: 10, sortname: 'id', viewrecords: true, sortorder: "desc", caption: "List Employee Details" }); </script>
So in this case i am manually writing the column names such as “FirstName”, “LastName” , etc , instead of relying on html templeted helpers such as Html.DisplayFor(modelitem=>modelitem.FirstName) . so I will lose the benefits of having strongly typed views. also the generated field names and their values will not be based on what has been defined inside the data annotation such as [DisplayName("First Name")] . So does this mean if I use jqGrid or other web grids, i will lose the effect of any data annotations such as DisplayName, since I will be manually writing the field names on each view ?.
Also all the examples which i read about jqGrid pass json to the Grid. So does jqGrid accept Model objects passed from action methods to view or it only work with json ?
Now when I create a new item inside the jqGrid, I will do this inside a jquery dialog and not inside normal view.so this means that the Data annotation used for validation which I define inside my model class such as [Required], [Length] will not have any effect inside the jquery dialogs , is this correct ?. Because from my current experience with jquery dialogs they will ignore DataAnnotation defined inside the Model class, also if I add error inside ModelState provided by asp.net mvc , then I will not be able to show the modelstate errors inside the dialog if an exception occurred in the Post Create action method , ?
Can anyone advice on these points and if they are valid when using web grids with asp.net mvc ?