asp.net mvc 3将“ URL”从“ /”更改为“?id =”

问题描述

| 我正在使用MVC3。页面内容来自sql数据库。当我尝试使用Javascript传递变量时,我注意到一个问题。当url显示目录/页面名称时不起作用,但是如果url是directory?= pagename则它起作用!任何想法,为什么以及如何将URL更改为?= id。 这是动作链接
<%: Html.ActionLink(\"Go\",\"CourseContent\",new { id = Model.ID })%>
全局路由
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 }
      );
    }
这是控制器:
public virtual ActionResult CourseContent(long id)
{
   Course requestedCourse = _courseSvc.GetCourse(id);
   if (requestedCourse == null)
       return new HttpNotFoundResult();

    string loggedInUserName = HttpContext.User.Identity.Name;
    string loggedInRoleName = _membershipSvc.GetRoleForUser(loggedInUserName);

    if (_courseSvc.DetermineIfTheUserCanAttendCourse(id,Request.IsAuthenticated,loggedInUserName,loggedInRoleName))
       return View(requestedCourse);

    return RedirectToAction(\"Index\");
}
提前致谢     

解决方法

        它应该与/ controller / action / id一起使用,但是您始终可以执行以下操作:
public static void RegisterRoutes(RouteCollection routes)
{
  routes.IgnoreRoute(\"{resource}.axd/{*pathInfo}\");

  routes.MapRoute(
    \"Default\",// Route name
    \"{controller}/{action}?id={id}\",// URL with parameters
    new { controller = \"Home\",action = \"Index\",id = UrlParameter.Optional }
  );
}