2017-05-18 14 views
0

私はMVCを使用した.NETプロジェクトで作業しており、同じページのセクションを指すリンクを作成する必要があります。MVCページ内のリンク

次のコードは、MVCなしでうまく機能:

<a href="#section1">Section 1</a> 
<div id="section1"> 
    <h1>Section 1</h1> 
</div> 

今これは私の本当のURLです: http://localhost:17338/MarketingCustomers/CleanData/1/1150119

そして私はURLので、ID = customerErrorSectionとdiv要素にリンクできるようにする必要があります次のようになります。 http://localhost:17338/MarketingCustomers/CleanData/1/1150119#customerErrorSection

URLの末尾に「#customerErrorSection」を追加する必要があります。

しかし、MVCのルーティングは、これは動作していない私のコードで、私はRouteConfigで遊んでてきたが、私は、私は必要なURLを作成する方法がわからない http://localhost:17338/MarketingCustomers/CleanData/1/1150119#/customerErrorSection

にURLを変更します。

routes.MapRoute(
         name: "MarketingDataClean_CustomerErrorSection", 
         url: "MarketingCustomers/CleanData/{systemSourceId}/{systemSourceCustomerId}/{#customerErrorSection}", 
         defaults: new { controller = "MarketingCustomers", action = "CleanData", systemSourceId = "", systemSourceCustomerId = "" } 
        ); 

ありがとうございました!

+0

URLの '# '部分はサーバー側に届くべきではないので、それをルートに追加する必要はありません –

答えて

0

。 #部分をそのまま残しておきます。

その後、
routes.MapRoute(name: "MarketingDataClean_CustomerErrorSection", 
       url: "MarketingCustomers/CleanData/{systemSourceId}/{systemSourceCustomerId}", 
       defaults: new { controller = "MarketingCustomers", action = "CleanData", systemSourceId = "", systemSourceCustomerId = "" }); 

そして、URLを使用します。 http://localhost:17338/MarketingCustomers/CleanData/1/1150119#customerErrorSection

あなたがUrl.Actionヘルパーを使用したい場合は、このようにそれを使用します。

@Url.Action("CleanData", "MarketingCustomers", new { systemSourceId = 1, systemSourceCustomerId = 1150119})#customerErrorSection 
0

試してみてください。私は本当にここでの問題を理解していない

routes.MapRoute(
    name: "MarketingDataClean_CustomerErrorSection", 
    url: "MarketingCustomers/CleanData/{systemSourceId}/{systemSourceCustomerId}/#customerErrorSection", 
    defaults: new { controller = "MarketingCustomers", action = "CleanData", systemSourceId = "", systemSourceCustomerId = "" } 
); 
+0

ありがとう、私は私の仕事で解決策を持っています。 – MarcosF8

0

私は、今、次のコードの作品を​​近く取得していますビューでは問題ありませんが、部分ビューの内側に配置するともう機能しません。

<ul> 
<li><a href="#section1">Section 1</a></li> 
<li><a href="#section2">Section 2</a></li> 
<li><a href="#section3">Section 3</a></li> 
<li><a href="#section41">Section 4-1</a></li> 
<li><a href="#section42">Section 4-2</a></li> 
</ul> 
<div id="section1"> 
<h1>Section 1</h1> 
</div> 
<div id="section2"> 
<h1>Section 2</h1> 
</div> 
<div id="section3"> 
<h1>Section 3</h1> 
</div> 
<div id="section41" class="container-fluid"> 
<h1>Section 4 Submenu 1</h1> 
</div> 
<div id="section42" class="container-fluid"> 
<h1>Section 4 Submenu 2</h1> 
</div> 
0

私はそれらのすべてのIDに配置する必要があり、他のdivまたはパネルの内側

、問題を発見:

<a href="#mainDiv#section2">Section 2</a> 

ディビジョン1:mainDiv、およびディビジョン2:section2の

もう一度お返事ありがとうございます!

関連する問題