I am using MVC 3. The page contents come from SQL database. I notice a problem when I try to pass variables using Javascript. It does not work when the url showing directory/pagename, however it works if the url is directory?=pagename!! Any idea why and how can I change the url to be ?=id.
Here is the action link:
<%: Html.ActionLink("Go", "CourseContent", new { id = Model.ID })%>
Routing in Global
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 }
);
}
and here is the controller:
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");
}
Thanks in advance
It should work with /controller/action/id, but you can always do something like: