将参数从MVC视图传递给使用jQuery的操作

pis*_*isi 2 javascript asp.net-mvc jquery asp.net-mvc-3

我想通过以下jQuery代码将参数从视图传递给动作,但我没有成功传递参数.我错过了什么吗?

$('li').click(function () {  
employeeID = $(this).attr('id');    
window.location.href = '/ApproveWork/GetEmployeeDays/'+employeeID; 
});
Run Code Online (Sandbox Code Playgroud)

控制器:

[HttpGet]
public ActionResult GetEmployeeDays(string userCode)
{
     .....
    return View("GetEmployeeDays", model);
}
Run Code Online (Sandbox Code Playgroud)

从Global.asax路由

public static void RegisterRoutes(RouteCollection routes)
 {
   routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
   routes.MapRoute(
          "Default", // Route name
          "{controller}/{action}/{id}", // URL with parameters
           new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );          
  }
Run Code Online (Sandbox Code Playgroud)

PS我试图使用AJAX jQuery函数,但这并没有返回我在Action中指定的视图.

Nin*_*Nye 7

您的javascript是否在视图页面上

如果是这样,请使用Url.Action帮助程序以正常方式构建URL

var url = '@Url.Action("Action", "Controller", new {parametername = "REPLACEME"})';
window.location.href = url.Replace('REPLACEME', parameter_value);
Run Code Online (Sandbox Code Playgroud)

更新为客户端变量帐户 *更新2:更新错误*