使用AJAX的MVC4菜单 [英] MVC4 Menus with AJAX
本文介绍了使用AJAX的MVC4菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用ajax和MVC从数据库创建垂直菜单。 Ajax显示内部错误。我坚持这个,我想从数据库创建菜单和子菜单
我的代码
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
$.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
[HttpPost]
public ActionResult GetMenu()
{
var res = from cust in db.SHP_Categories select cust; ;
return View(res);
}
推荐答案
.ajax({
url:' @ Url.Action(GetMenu,Products)',
类型:' POST',
成功: function (result){
alert(' 成功');
console .log(data);
},
错误: function (错误){
alert (错误);
}
});
.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
[HttpPost]
public ActionResult GetMenu()
{
var res = from cust in db.SHP_Categories select cust; ;
return View(res);
}
从action方法返回数据的一种方法是使用json.Below只是一个简单的伪代码你可能需要根据你的申请修改
你可以返回json作为
返回Json(你的型号);
您可以使用ajax通过在
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中提供以下参数来调用您的操作方法({
< br $>
...
dataType:json,
contentType:'application / json'
data:JSON.stringify (数据),
成功:功能(d){
//检索数据
}
.ajax({
...
dataType: json,
contentType:'application/json'
data: JSON.stringify(data),
success: function(d) {
//retreive the data
}
这篇关于使用AJAX的MVC4菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文