|
I am new to jqgrid, I learned from here and tried to implement this in my project. But I am getting the error:
Quote: The parameters dictionary contains a null entry for parameter 'page' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.JsonResult DisplayUsers(System.String, System.String, Int32, Int32)' in 'MyProject.Controllers.AppUserController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Exception Details: System.ArgumentException: The parameters dictionary contains a null entry for parameter 'page' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.JsonResult DisplayUsers(System.String, System.String, Int32, Int32)' in 'MyProject.Controllers.AppUserController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
My controller class:
public class AppUserController : Controller
{
MyProjectContext db = new MyProjectContext();
public JsonResult DisplayUsers(string sidx, string sord, int page, int rows)
{
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
var displayUsers = db.app_user.Select(
a => new
{
a.id,
a.username,
a.password,
a.user_role,
a.date_of_register,
a.is_active
});
int totalRecords = displayUsers.Count();
var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);
if (sord.ToUpper() == "DESC")
{
displayUsers = displayUsers.OrderByDescending(s => s.username);
displayUsers = displayUsers.Skip(pageIndex * pageSize).Take(pageSize);
}
else
{
displayUsers = displayUsers.OrderBy(s => s.username);
displayUsers = displayUsers.Skip(pageIndex * pageSize).Take(pageSize);
}
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = displayUsers
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
}
displayUsers.js
$(function () {
$("#ListGrid").jqGrid({
url: "/AppUser/DisplayUsers",
datatype: 'json',
mtype: 'Get',
colNames: ['Id', 'User Name', 'User Role', 'Date Of Register', 'Status'],
colModel: [
{ key: true, hidden: true, name: 'id', index: 'id', editable: true },
{ key: false, name: 'username', index: 'username', editable: true },
{ key: false, name: 'user_role', index: 'user_role', editable: true },
{ key: false, name: 'date_of_register', index: 'date_of_register', editable: true, formatter: 'date', formatoptions: { newformat: 'd/m/Y' } },
{ key: false, name: 'is_active', index: 'is_active', editable: true, edittype: 'select', editoptions: { value: { 'A': 'Active', 'I': 'InActive' } } }],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [10, 20, 30, 40],
height: '100%',
viewrecords: true,
caption: 'Users',
emptyrecords: 'No records to display',
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
Id: "0"
}
});
});
Please help me with this.
|
|
|
|
|
can you please share us DB first of this project with Mvc 5 and EF 6?
|
|
|
|
|
I got this error message when editing.
"Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries." please help.
Here is code for Edit ActionMethod
<pre lang="c#">
public string Edit(Client client)
{
string msg;
try
{
if (ModelState.IsValid)
{
db.Entry(client).State = EntityState.Modified;
db.SaveChanges();
msg = "Save Successfully";
}
else
{
msg="Validation data not successful";
}
}
catch(Exception ex)
{
msg = "Error occured:" + ex.Message;
}
return msg;
}</pre>
|
|
|
|
|
It's working for me. but some time i am getting Failed to load resource: the server responded with a status of 500 (Internal Server Error).
can you suggest me why it's error getting.
Thanks.
|
|
|
|
|
Please make sure you have Create actionmethod in your controller.
|
|
|
|
|
Hi Dileep,
Above all, thanks for your great guidance and assistance. I have started using Jqgrid and now I am trying to implement Sub Grid. I have no clue, please give me a reference, tutorial or example.
Thanks in advance.
|
|
|
|
|
Hi,
Thank you. JqGrid subrid is very simple.
Please go through the example in below mentioned url
http://www.trirand.com/blog/jqgrid/jqgrid.html[^]
under left panel select JQgrid Grouping example.
And its like we need to had some properties in JQGrid like
grouping:true,
groupingView : {
groupField : ['name']
},
Thanks and regards,
Dileep
|
|
|
|
|
Great articles..thanks a lot..
|
|
|
|
|
lifesaver. Thanks for sharing
|
|
|
|
|
cheers
|
|
|
|
|
Thank you..
|
|
|
|
|
Hi,
your article is great, but I can't figure out what to do if TodoList object would have a navigation property... I mean I'm trying to create a todolist-like application, but I have transactions. AA transaction can have a category, so the structure is like:
public class Transaction {
public int Id {get; set;}
public string Comment {get; set;}
public Category Category {get; set;}
}
public class Category {
public int Id {get;set;}
public string Name {get;set;}
}
If I try to edit a row in my grid which lists transactions, when I check the transaction object in the controller method
public string Edit(Transaction transaction)
i found that transaction.Category is null, or worst, a new Category object with some data inside (I guess it's the Id, but in the Name property...)
So could you please help me how can I bind my complex object correctly?
Thanks!
|
|
|
|
|
Hi,
Very interesting question.
I guess you want a category field( dropdown field) which is like (1 to many relationship) to be displayed in transaction page.
For this to happen you have to slight modification in you model as mentioned below. Use "CategoryId" which will become the foreign key to category in transaction table
public class Transaction {
public int Id {get; set;}
public string Comment {get; set;}
public int CategoryId{get;set;}
public Category Category {get; set;}
}
public class Category {
public int Id {get;set;}
public string Name {get;set;}
}
Step 2: After doing this you need to populate the category field dropdown from the controller to Jqgrid. So then you will be able to see the categoryID value in your model property.
You have to do little R& D to populate the dropdown from the controller level.
or use a seperate screen for creating screen which may contain complex objects like dropdown, listbox etc. and use Jqgrid to display the records.
Let me know if you have any more clarifications. Please do subscribe to my channel. So that i will be Posting the usefull videos. Will be covering most of the concepts like 1 to many, Many to Many relationship concepts etc.
Thanks
|
|
|
|
|
How to show the validation message in the add and edit pop up windows
|
|
|
|
|
|
ADD and Edit operations not working shows 505 error
|
|
|
|
|
Please follow the video and implement it accordingly.
Also check all required Jqgrid plugins are present in the same order which i mentioned in the demo.
Also you can download the sample example from codeplex and check it.
Thanks
Dileep.
|
|
|
|
|
HI, I'm a fresher in .net Every thing in my project works but in JQgrid the crud operations are not displaying. please any one help me in that.
|
|
|
|
|
Hi,
It should be working fine, you can also watch in video. can you download the source and check it once.
Also try to implement it step by step following the video.
Source Code:https://dotnetsourcedileep.codeplex.com/[^]
Video:https://www.youtube.com/watch?v=OhJtxRvgeK0&list=PLdmgFSerzv2Lhj5dFrD75sz26qGdxpo8Z[^]
thanks.
|
|
|
|
|
After editing ,'Validation data not successful' is shown. I am getting objTodo.Id = 0 in the controller.
|
|
|
|
|
|
The code works fine and no issues. My question may be beyond the scope of this article.I enabled the search as shown below
.navGrid('#pager', { edit: true, add: true, del: true, search: true, refresh: true },
The search popup window appears but the search conditions are not working and it always shows the full list.
Could you help?
Note : The same code if we run in html, it works and I guess MVC stops the search.
Best wishes
Balakrishnan
bala.in@rediffmail.com
|
|
|
|
|
|
You are great and thank you for your time to plan, write and publish this post.
Best wishes
Balakrishnan
bala.in@rediffmail.com
|
|
|
|
|
I downloaded your code first example. It works great! Thanks.
How do you add filter to your example?
In your TodoList.js code the search property was set to false. So I set it to true like this:
.navGrid('#pager', { edit: true, add: true, del: true, search: true, refresh: true },
When I set it to true the filter magnifying glass icon appears on the bottom toolbar.
After I set the property to true this is a video demo of me running your example and trying to use the filter.
As you can see... after I set the search property to true, the filter is still not working.
http://youtu.be/O-T7WxBbsBc[^]
What else do I have to do to get the filter to work in your example?
Do I have to add a javascript function?
or
Do I have to add a C# method?
or
Do I have to set some other property?
|
|
|
|
|