JsonResult with MVC2RC

In the few days, I tried to pass JsonResult from Controller to View (I used MVC2RC and S#arpArchitecture) but I can’t do it although I did in MVC1 well done. Today, I found the article of  David Hayden which is named “JsonResult and JsonRequestBehavior in ASP.NET MVC 2“. That is the article I need but I still not did. So, I take around the world with Google, I found one post additional of  Daoming about this problem. It is JSON Error in MVC2: request has been blocked because sensitive information.

These is the way to fix this (copy from blog of Daoming)

53 [AcceptVerbs(HttpVerbs.Get)]

54 public ActionResult GetAllData(string sidx, string sord, int page, int rows)

55 {

56 var allcat = this.m_CategoryRepository.GetAll().AsQueryable();

57 int PageIndex = page – 1;

58 int PageSize = rows;

59 int TotalRow = allcat.Count();

60 int TotalPage = (int)Math.Ceiling((float)TotalRow / (float)PageSize);

61

62

63 var current = from categories in allcat

64 .OrderBy(sidx + ” “ + sord)

65 .Skip(PageIndex * PageSize)

66 .Take(PageSize)

67 select categories;

68

69 var jsonData = new

70 {

71 total = TotalPage,

72 page = page,

73 records = allcat.Count(),

74 rows = (

75 from cat in current

76 select new

77 {

78 i = cat.Id,

79 cell = new string[] {

80 cat.Id.ToString(), cat.CategoryName

81 }

82 }).ToArray()

83 };

84 return Json(jsonData,JsonRequestBehavior.AllowGet);

85 }

Thanks David Hayden and Daoming so much.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s