我在使用MVC的.NET项目中工作,我需要将工作链接指向同一页面上的某个部分。
以下代码在没有MVC的情况下运行良好:
<a href="#section1">Section 1</a>
<div id="section1">
<h1>Section 1</h1>
</div>
现在这是我的真实网址: http://localhost:17338/MarketingCustomers/CleanData/1/1150119
我需要能够使用id = customerErrorSection与div链接,因此URL应如下所示: http://localhost:17338/MarketingCustomers/CleanData/1/1150119#customerErrorSection
所以我需要在URL的末尾添加“#customerErrorSection”。
但是MVC路由将URL更改为 http://localhost:17338/MarketingCustomers/CleanData/1/1150119#/customerErrorSection
我一直在使用RouteConfig,但我不知道如何创建我需要的URL,这是我的代码无效:
routes.MapRoute(
name: "MarketingDataClean_CustomerErrorSection",
url: "MarketingCustomers/CleanData/{systemSourceId}/{systemSourceCustomerId}/{#customerErrorSection}",
defaults: new { controller = "MarketingCustomers", action = "CleanData", systemSourceId = "", systemSourceCustomerId = "" }
);
感谢您的帮助!
答案 0 :(得分:0)
尝试:
routes.MapRoute(
name: "MarketingDataClean_CustomerErrorSection",
url: "MarketingCustomers/CleanData/{systemSourceId}/{systemSourceCustomerId}/#customerErrorSection",
defaults: new { controller = "MarketingCustomers", action = "CleanData", systemSourceId = "", systemSourceCustomerId = "" }
);
答案 1 :(得分:0)
我真的不明白这里的问题。只需离开#部分即可。
routes.MapRoute(name: "MarketingDataClean_CustomerErrorSection",
url: "MarketingCustomers/CleanData/{systemSourceId}/{systemSourceCustomerId}",
defaults: new { controller = "MarketingCustomers", action = "CleanData", systemSourceId = "", systemSourceCustomerId = "" });
然后使用网址: http://localhost:17338/MarketingCustomers/CleanData/1/1150119#customerErrorSection
如果您想使用Url.Action
助手,请按照以下方式使用:
@Url.Action("CleanData", "MarketingCustomers", new { systemSourceId = 1, systemSourceCustomerId = 1150119})#customerErrorSection
答案 2 :(得分:0)
我现在越来越近了,下面的代码在View中运行正常,但是当我把它放在局部视图中时不再起作用了。
<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>
答案 3 :(得分:0)
我发现了问题,
在其他div或面板内部,需要输入所有这些ID:
<a href="#mainDiv#section2">Section 2</a>
Div 1:mainDiv和Div 2:section2
再次感谢大家的帮助!