EasyUI Forum
September 14, 2025, 03:51:13 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: MVC3 + Json + uasyui combobox  (Read 8165 times)
hahadelphi
Newbie
*
Posts: 8


View Profile
« on: July 15, 2014, 01:38:24 AM »

I am using MVC3 and combobox

my cshtml is
Code:
<script type="text/javascript">

    $('#c_MENU_ID').combobox({
        url: '@Url.Action("GetMenu","Menu")'
    });
</script>
and action is

Code:
public JsonResult GetFatherMenu()
{
    var q = from e in db.MENUS_V
    where e.MENU_ID > 0
    select new
    {
menu_id = e.MENU_ID,
menu_name = e.MENU_NAME
    };
    var result = q.ToList();
    Dictionary<string, object> json = new Dictionary<string, object>();
    json.Add("total", q.ToList().Count);
    json.Add("rows", result);
    return Json(json, JsonRequestBehavior.AllowGet);
}


Now i know that the combo box only accept
[{
"MENU_ID":1,
"MENU_NAME":"text1"
},{
"MENU_ID":2,
"MENU_NAME":"text2"
}]

not
{"rows":
[{
"MENU_ID":1,
"MENU_NAME":"text1"
},{
"MENU_ID":2,
"MENU_NAME":"text2"
}]
}

what can i do in the action to return the correct json? Thanks
« Last Edit: July 15, 2014, 01:52:08 AM by hahadelphi » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 15, 2014, 01:43:05 AM »

Please use the 'loadFilter' function to convert your original data to the standard data format.
Code:
$('#c_MENU_ID').combobox({
    url: ...,
    loadFilter:function(data){
    return data.rows;
    }
});
Logged
hahadelphi
Newbie
*
Posts: 8


View Profile
« Reply #2 on: July 15, 2014, 02:02:13 AM »

thank you!

i also use this action, it works

Code:
        public JsonResult GetFatherMenu()
        {
  var q = from e in db.MENUS_V
    where e.MENU_ID > 0
    select new
    {
menu_id = e.MENU_ID,
menu_name = e.MENU_NAME
    };
            var result = q.ToList();
            JsonResult json = new JsonResult();
            json.Data = q.ToList();
            return Json(json.Data, JsonRequestBehavior.AllowGet);
        }

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!