Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I need to create vertical menus from database using ajax and MVC. Ajax showing internal error.And i am stuck with this and i want to create menus and sub menus from database

my code


JavaScript
$.ajax({
         url: '@Url.Action("GetMenu", "Products")',
         type: 'POST',
         success: function (result) {
             alert('Success');
             console.log(data);
         },
         error: function (error) {
                           alert(error);
         }
     });


Product controller defenition for get menu
C#
[HttpPost]
       public ActionResult GetMenu()
       {
           var res = from cust in db.SHP_Categories select cust; ;
           return View(res);
       }
Posted
Updated 13-Nov-14 18:47pm
v3
Comments
[no name] 14-Nov-14 0:49am    
Do you have a viewmodel that you are passing in the view?
And you haveplaced two semicolons by mistake please check that.
And one more thing this LINQ returns more than one element. The Action method seems to be wrong.
Member 10212775 14-Nov-14 1:05am    
no i dont have any model for this and corrected the semicolen..

One way to return the data from the action method is by using json.Below is just a simple pseudo code which you may need to modify as per your application

you can return json as
return Json(your model);

You can call your action method using ajax by providing the below parameters in the $.ajax({

...
dataType: json,
contentType:'application/json'
data: JSON.stringify(data),
success: function(d) {
//retreive the data
}
 
Share this answer
 
Refer below which has a similar one, may be useful

http://www.dotnetcurry.com/showarticle.aspx?ID=811[^]
 
Share this answer
 

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