Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Here is my View
JavaScript
<script>
    function filltable() {
        alert("in other method");
        window.oTable = $("#table").dataTable({
            "bServerSide": true,
            "sAjaxSource": "Url.Action(User/GetResult)",
            "sAjaxDataProp": "aaData",
            "aoColumns": [
                { "mDataProp": "USER_NAME" },
                { "mDataProp": "EMAIL_ID" },
                { "mDataProp": "MOBILE_NO" }
            ],
            "bJQueryUI": true,
            "bProcessing": false
        });
    }
</script>


Why sAjaxSource doesn't redirect to the url? Please help...

UPDATE

Now it is rediecting to Url.bt it doesnt show data which is coming from controller in this format in mvc2---->

{[
  {
    "USER_NAME": "alpa",
    "MOBILE_NO": "000",
    "EMAIL_ID": "alpa.sae",
    "COLOR_NAME": "Red",
    "COLOR_ID": 0
  },
  {
    "USER_NAME": "alpas",
    "MOBILE_NO": "000",
    "EMAIL_ID": "alpa.sae",
    "COLOR_NAME": "Green",
    "COLOR_ID": 0
  }
]}


My controller



[HttpGet]
        public JsonResult GetResult()
        {
            JArray JsonArray = new JArray();
            JObject jo = new JObject();

            
             
            List plist = new List();
            User tUser = new User();
           
            tUser.USER_NAME = "alpa";
            tUser.EMAIL_ID = "alpa.sae";
            tUser.MOBILE_NO = "000";
            tUser.COLOR_NAME = "Red";
            plist.Add(tUser);

            tUser = new User();
            tUser.USER_NAME = "alpas";
            tUser.EMAIL_ID = "alpa.sae";
            tUser.MOBILE_NO = "000";
            tUser.COLOR_NAME = "Green";
            plist.Add(tUser);

            JsonArray = (JArray)JToken.FromObject(plist);

            jo["Message"] = "Data Saved Succeffully";
            jo["data"] = JsonArray;
           // return Json(plist, JsonRequestBehavior.AllowGet);
            var aaData = new Response(true, "Contact Successfully Submitted", jo["data"].ToString());
            return Json(aaData);
        }
  }
Posted
Updated 12-Feb-14 0:46am
v4
Comments
Member 10435696 12-Feb-14 6:29am    
Now it is rediecting to Url.bt it doesnt show data which is coming from controller in this format in mvc2---->

{[
{
"USER_NAME": "alpa",
"MOBILE_NO": "000",
"EMAIL_ID": "alpa.sae",
"COLOR_NAME": "Red",
"COLOR_ID": 0
},
{
"USER_NAME": "alpas",
"MOBILE_NO": "000",
"EMAIL_ID": "alpa.sae",
"COLOR_NAME": "Green",
"COLOR_ID": 0
}
]}


My controller



[HttpGet]
public JsonResult GetResult()
{
JArray JsonArray = new JArray();
JObject jo = new JObject();



List<user> plist = new List<models.user>();
User tUser = new User();

tUser.USER_NAME = "alpa";
tUser.EMAIL_ID = "alpa.sae";
tUser.MOBILE_NO = "000";
tUser.COLOR_NAME = "Red";
plist.Add(tUser);

tUser = new User();
tUser.USER_NAME = "alpas";
tUser.EMAIL_ID = "alpa.sae";
tUser.MOBILE_NO = "000";
tUser.COLOR_NAME = "Green";
plist.Add(tUser);

JsonArray = (JArray)JToken.FromObject(plist);

jo["Message"] = "Data Saved Succeffully";
jo["data"] = JsonArray;
// return Json(plist, JsonRequestBehavior.AllowGet);
var aaData = new Response(true, "Contact Successfully Submitted", jo["data"].ToString());
return Json(aaData);
}
}
Sampath Lokuge 12-Feb-14 6:35am    
Is your "Json(aaData)" returning correct data ?
Sampath Lokuge 12-Feb-14 6:30am    
Can you put your Action method's code snippet also ?
Member 10435696 12-Feb-14 6:33am    
i have posted it method name getresult
Member 10435696 12-Feb-14 6:40am    
Yes my json(aaData) is returning correct data..
{[
{
"USER_NAME": "alpa",
"MOBILE_NO": "000",
"EMAIL_ID": "alpa.sae",
"COLOR_NAME": "Red",
"COLOR_ID": 0
},
{
"USER_NAME": "alpas",
"MOBILE_NO": "000",
"EMAIL_ID": "alpa.sae",
"COLOR_NAME": "Green",
"COLOR_ID": 0
}
]}




1 solution

Please try is as below.

SQL
[HttpGet]
public JsonResult GetResult()
{

    //Your code here

    return Json(aaData,JsonRequestBehavior.AllowGet);
}
 
Share this answer
 
Comments
Member 10435696 12-Feb-14 6:57am    
Still the same..data doesnt show up in table..
Sampath Lokuge 12-Feb-14 7:11am    
Are their any errors on JS file ? Check by using chrome dev tools.
Member 10435696 12-Feb-14 7:32am    
Uncaught TypeError: Cannot read property 'length' of undefined jquery.dataTables.js:2541
Sampath Lokuge 12-Feb-14 7:54am    
Where you use 'length' property ? I couldn't see that on above code.
Member 10435696 15-Feb-14 7:23am    
Above issues are resolved..Plz have a look at below link
http://www.codeproject.com/Questions/727843/How-to-disable-textbox-on-checkbox-check-is-true-v

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900