喜家伙我从我的观点这个jQuery Ajax调用,它看起来像这样:路由在Global.asax中不注册
$("select#Colors").change(function() {
var color = $("#Colors > option:selected").attr("value");
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "FindProducts/" + color,
data: "{}",
dataType: "json",
success: function(data) {
.....
}
});
});
而且继承人的操作方法在我的HomeController
public JsonResult FindProductsByColorID(string color)
{
// List of Products
List<Product> productList = new List<Product>{
new Product{......}
};
// return Json result using LINQ to SQL
return new JsonResult
{
Data = (from p in productList
where p.Color == color
select p).ToArray<Product>()
};
}
我的目标是使用JQuery.ajax调用方法FindProductsByColorID。并且由于名称有点冗长,我将url注册到global.asax路由表中。
routes.MapRoute(
"FindProducts",
"FindProducts/{color}",
new { controller = "Home", action = "FindProductsByColorID", color = ""}
);
因为某些原因路由Ajax调用,当我测试了Firebug的过程中并没有发生,该网址显示本地主机/主页/ FindProducts /红色。当然,结果未能加载因为在家庭控制器中没有FindProducts方法。我是否在路由选择方面做错了什么?因为当我在一个新的新项目上测试它时,它工作得很好,但是当我在正在进行的项目中完成时,它只是失败了。任何解决方案将非常感谢!
哦哇,我爱你的家伙! – Ari 2010-09-01 03:22:31
不错,不客气。 – Hogan 2010-09-01 03:23:33