titi
titi

Reputation: 1035

How to get the JSON from the controller to display in the view of ASP.net MVC 2

I am trying to query data from a database, in order to take it to create the main menu in my ASP.NET MVC 2 web site.

This is the code in my controller :

public JsonResult GetMenu(string id)
{
  JsonResult jr  = new JsonResult();
  var ien_menu = (    
      from d in this.DataContext.Departments                                                    
      join c in this.DataContext.Categories                                  
      on d.ID equals c.DepartmentID   
      join i in this.DataContext.Items on 
      c.ID equals i.CategoryID
      where d.Active == 1
         && d.ActiveInWeb >0
         && c.Active > 0
         && c.ActiveInWeb >0
         && i.Active > 0
      select d
    ).Distinct()
     .OrderBy(s=>s.Name);
  jr.Data = ien_menu.ToList();
  jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
  return jr;
}

But I really have no idea how to take this data and display it in my partial views. What do I need to do?

Upvotes: 0

Views: 193

Answers (1)

Sachin
Sachin

Reputation: 343

How are you calling this controller action? You can use jQuery to get the Json results if you are loading via ajax. Look at the success function to get the data - http://api.jquery.com/jQuery.ajax/

Upvotes: 1

Related Questions