我应该如何格式化一个路径,以便在jQuery中使用MVC路由?我返回Json,与另一个SO post非常相似。一切都在当地很好,但部署只是炸弹出来。查询运行,但检查萤火虫它看起来像jQuery.Get()的成功回调不会触发。在MVC 3中使用路由工作的URL路径
最新的更新
我现在唯一的问题是有特殊字符。任何时候我通过一个“。”或“@”作为MVC路线的一部分我得到一个404.删除这些特殊字符也会消除错误。您可以在下面看到控制器和路由逻辑。
任何时候我通过'。'作为URL的一部分,它会炸弹。与时期有什么关系?
查询格式 /服务/索引/ {EMAIL}的 -
破碎E.G. /Service/Index/[email protected](404)
工作E.G. /服务/索引/ bmackeyfoocom(200)
旧的东西(供参考)
我试过"/Service/Index/email", "../Service/Index/email","../../Service/Index/email"
,但没有什么工作。
$email.blur(function()
{
var email = $(this).val(); // grab the value in the input
var url = '@Url.Action("Index", "Service")'; //this is calling MVC page, not normal aspx so I can't pass it as a query param (at least as far as I am aware)
$.get(url + '/' + email.toString(),
更新
我停下我的硬编码URL。本地运行完美。我在DEV服务器上运行时仍然出现404错误。该URL看起来正确。我传递一个字符串值时遇到404错误,但如果将参数更改为int,则会返回“null”(带引号)。这使我相信的东西是错误与我的控制器实现或路由:
public ActionResult Index(string email)
{
string emailAddress = email;
GetActiveDirectoryInformation adInfo = new GetActiveDirectoryInformation();//calls entity framework
Common_GetAdInfo_Result result = adInfo.Lookup(email: emailAddress);
string jsonResponse = System.Web.Helpers.Json.Encode(result);
return Json(jsonResponse,JsonRequestBehavior.AllowGet);
}
的Global.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Service",
"Service/Index/{email}",
new { controller = "Service", action = "Index", email = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
使用萤火虫网络标签查看正在调用的网址,以及服务器响应是什么。这应该给你一个线索。 – NerdFury 2011-03-18 21:59:07
我可以问你想做什么吗?这是为了验证吗? – Paul 2011-03-18 22:15:33
@保罗这是填充一堆雇员信息给他们的电子邮件地址。 – 2011-03-19 01:44:06