0

I have jqgrid on view(ASP.NET MVC) and I am parsing the grid data into JSON.And I am sending this JSON string to controller like this -

[{"CSSMENUSETTINGID":"7","ISPUBLISHED":"1","DISPORDER":"<input class=\"txt width70\" onchange=\"javascript:fnValidateEmpty(this);\" onkeypress=\"javascript:return fnIsNumber(event,this)\" name=\"txtBox\" id=\"txt_DisplayOrder_7\" value=\"0\" type=\"text\">","MENUNAME":"Menu_0","DISPTXT":"<input class=\"txt\" placeholder=\"Display Text\" name=\"txtBox\" id=\"txt_DisplayText_7\" value=\"Menu_Dis_0\" type=\"text\">","DISPURL":"<input class=\"txt\" onchange=\"javascript:return fnIsURL(this)\" placeholder=\"Navigation URL\" name=\"txtBox\" id=\"txt_DisplayURL_7\" value=\"\" type=\"text\">","ISDISP":"<input id=\"chk_Display_7\" value=\"1\" type=\"checkbox\">"},{"CSSMENUSETTINGID":"8","ISPUBLISHED":"1","DISPORDER":"<input class=\"txt width70\" onchange=\"javascript:fnValidateEmpty(this);\" onkeypress=\"javascript:return fnIsNumber(event,this)\" name=\"txtBox\" id=\"txt_DisplayOrder_8\" value=\"1\" type=\"text\">","MENUNAME":"Menu_1","DISPTXT":"<input class=\"txt\" placeholder=\"Display Text\" name=\"txtBox\" id=\"txt_DisplayText_8\" value=\"Menu_Dis_1\" type=\"text\">","DISPURL":"<input class=\"txt\" onchange=\"javascript:return fnIsURL(this)\" placeholder=\"Navigation URL\" name=\"txtBox\" id=\"txt_DisplayURL_8\" value=\"\" type=\"text\">","ISDISP":"<input id=\"chk_Display_8\" value=\"1\" type=\"checkbox\">"},{"CSSMENUSETTINGID":"9","ISPUBLISHED":"1","DISPORDER":"<input class=\"txt width70\" onchange=\"javascript:fnValidateEmpty(this);\" onkeypress=\"javascript:return fnIsNumber(event,this)\" name=\"txtBox\" id=\"txt_DisplayOrder_9\" value=\"2\" type=\"text\">","MENUNAME":"Menu_2","DISPTXT":"<input class=\"txt\" placeholder=\"Display Text\" name=\"txtBox\" id=\"txt_DisplayText_9\" value=\"Menu_Dis_2\" type=\"text\">","DISPURL":"<input class=\"txt\" onchange=\"javascript:return fnIsURL(this)\" placeholder=\"Navigation URL\" name=\"txtBox\" id=\"txt_DisplayURL_9\" value=\"\" type=\"text\">","ISDISP":"<input id=\"chk_Display_9\" value=\"1\" type=\"checkbox\">"}]

My JQGrid contains some input field columns like textbox and checkbox.

And my problem is when I am getting the JSON string at controller I am getting the input column html instead of cell value like this -

"DISPORDER":"<input class=\"txt width70\" onchange=\"javascript:fnValidateEmpty(this);\" onkeypress=\"javascript:return fnIsNumber(event,this)\" name=\"txtBox\" id=\"txt_DisplayOrder_7\" value=\"0\" type=\"text\">"

But I want only the value of jqgrid cell instead of html string.But I am not getting a proper way for this problem.

Onething that we can do is,by extracting a value from html string.But I dont thing it's a best way of this.

Can any one know's how to get value instead of html JSON string in c# ?

Hossam Barakat
  • 1,399
  • 9
  • 19
user3848036
  • 169
  • 2
  • 6
  • 17
  • no need to reinvent the wheel, you can use this library https://www.nuget.org/packages/Newtonsoft.Json/ – bto.rdz Jan 14 '15 at 06:31
  • hi,bto.rdz, thanks for your reply but I did not get you.Please give me any example. – user3848036 Jan 14 '15 at 06:38
  • run that packe in visual studio then you can use that code for free. this is the page of that library. they have tons of examples http://james.newtonking.com/json – bto.rdz Jan 14 '15 at 06:40

2 Answers2

0

Use Json.NET in your project.

First option is to create a model class reflecting the JSON fields that you're expecting and creating an array of this model deserialize the JSON to objects and use as you like for manipulation.

Second option is to use LINQ query and dynamic with the same library. See this answer here.

Community
  • 1
  • 1
George Taskos
  • 8,324
  • 18
  • 82
  • 147
0

Use following steps:

1) Add Json.NET from NuGet Package. 2) Create model class which contains whatever Json fields you may need 3) Use JsonConvert.DeserializeObject

Harish
  • 1