Routing confusion in ASP.NET MVC [duplicate]
context: I am currently developing my first MVC application, I am following the examples in the book "Pro ASP.NET MVC Framework 2" by Steven Sanderson. I followed the first chapters and I have implemented a similar application to the "SportStore" full code can be located at the following link http://pastie.org/2451370
The application has two controllers
1 .- NavController designed to implement a user menu using a user control "Menu.ascx"
2 .- PostEntryController designed to list the post belonging to a particular menu option
The problem arises when running the application in debug mode NavController generated links do not work for some reason the PostEntryController is not instantiated.
When I examine the source code generated aspx file is shown as (PostEntry/Index.aspx)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="ht开发者_Go百科tp://www.w3.org/1999/xhtml">
<head>
<link href="/MarsWeb/Content/Site.css" rel="stylesheet" type="text/css" />
<link href="/MarsWeb/Content/jquery.treeview.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/MarsWeb/Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="/MarsWeb/Scripts/jquery.treeview.js"></script>
<script type="text/javascript" src="/MarsWeb/Scripts/jquery-treeview-1.4.0.min
</script>
<script type="text/javascript">
$(function() {
$("#browser").treeview({collapsed: true,animated: "medium",control: "#categories",
unique: true,persist: "location"});})
</script>
<title>Posts</title></head>
<body>
<div id="header">
<div id="title">
<h1>Mars Ventas</h1>
</div>
</div>
<div id="categories">
<ul id="browser" class="filetree">
<li><span class="folder"><a href="/PostEntry/Index/0/1">Home</a></span></li>
<li><span class="folder"><a href="/PostEntry/Index/2/1">Ventas</a></span></li>
<li><span class="folder"><a href="/PostEntry/Index/3/1">Avance de Ventas</a></span></li>
<li><span class="folder"><a href="/PostEntry/Index/4/1">Browser</a></span></li>
</ul>
</div>
</html>
Can anyone help me?
This is Global.asax
routes.MapRoute("PostEntry", "PostEntry/{action}/{MenuItemId}/{page}", // Matches ~/MenuId
new { controller = "PostEntry", action = "Index", MenuItemId = (string)null },
new { page = @"\d+" }
);
routes.MapRoute("MenuItem", "PostEntry/{action}/{MenuItemId}", // Matches ~/MenuId
new { controller = "PostEntry", action = "Index", MenuItemId = (string)null, page = 1 }
);
routes.MapRoute(null, "", // Only matches the empty URL (i.e. ~/)
new { controller = "PostEntry", action = "Index", MenuItemId ="0", page = 1}
);
When I write the url in the address bar I can access the url
According to your description, I believe the link generation went wrong. So look at html source from the browser and see if the links are correctly generated.
精彩评论