Hi All,
I am using MVC3 in my application. In my controller i have to return Json data to bind my JQGrid.
Based on a condition, i want to build my Json data. For this i need to declare the variable
"var jsonData" (refer below code) and initialize it to some value initially, so that i can build the query and return it at last to bind the JQGrid.
I tried to initialize it in many ways like by giving empty string or assigning it to null etc. But i failed,please tell me How can i initialize it to null?
public JsonResult LoadByName(string txtSearchVal, string SearchBy)
{
//var jsonData= new list<string>;
if (SearchBy.ToUpper() == "FIRSTNAME")
{
var jsonData = new
{
records = tskgrp.UserDetails.Count(),
rows = (
from user in tskgrp.UserDetails
where (user.FirstName.StartsWith(txtSearchVal))
select new
{
i = user.ID,
cell = new string[] { user.ID.ToString(), user.FirstName, user.LastName, user.Active.ToString() }
}).ToArray()
};
}
if (SearchBy.ToUpper() == "LASTNAME")
{
var jsonData = new
{
records = tskgrp.UserDetails.Count(),
rows = (
from user in tskgrp.UserDetails
where (user.FirstName.Contains(txtSearchVal))
select new
{
i = user.ID,
cell = new string[] { user.ID.ToString(), user.FirstName, user.LastName, user.Active.ToString() }
}).ToArray()
};
}
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
Thanks in advance
Sheetal