簡體   English   中英

ASP.NET MVC中的路由混淆

[英]Routing confusion in ASP.NET MVC

上下文:我正在開發我的第一個MVC應用程序,我正在遵循Steven Sanderson的“Pro ASP.NET MVC Framework 2”一書中的示例。 我按照第一章和我已經實現了類似的應用程序,“SportStore”完整代碼可以在以下鏈接中找到http://pastie.org/2451370

該應用程序有兩個控制器

1 .- NavController旨在使用用戶控件“Menu.ascx”實現用戶菜單

2 .- PostEntryController旨在列出屬於特定菜單選項的帖子

在調試模式下運行應用程序時出現問題NavController生成的鏈接由於某種原因無法實現PostEntryController未實例化。

當我檢查生成的源代碼時,aspx文件顯示為(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="http://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>

誰能幫我?

這是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}
        );

當我在地址欄中寫下網址時,我可以訪問該網址

根據你的描述,我認為鏈接生成出錯了。 所以從瀏覽器中查看html源代碼,看看鏈接是否正確生成。

我修改了我的Site.Master並禁用了JavaScript,現在鏈接正常工作。 我目前正在閱讀以下鏈接來解決ASP.NET MVC Relative Paths這個問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM