我正在使用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,所以网址应该如下所示:http://localhost:17338/MarketingCustomers/CleanData/1/1150119#customerErrorSection
因此,我需要在URL的末尾添加"#customerErrorSection“。
但是MVC路由将URL更改为http://localhost:17338/MarketingCustomers/CleanData/1/1150119#/customerErrorSection。
我一直在玩RouteConfig,但我不知道如何创建我需要的网址,这是我的代码不工作:
routes.MapRoute(
name: "MarketingDataClean_CustomerErrorSection",
url: "MarketingCustomers/CleanData/{systemSourceId}/{systemSourceCustomerId}/{#customerErrorSection}",
defaults: new { controller = "MarketingCustomers", action = "CleanData", systemSourceId = "", systemSourceCustomerId = "" }
);
谢谢你的帮助!
发布于 2017-05-18 17:38:02
我不太理解这里的问题。去掉#部分就行了。
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
发布于 2017-05-18 17:35:27
尝试:
routes.MapRoute(
name: "MarketingDataClean_CustomerErrorSection",
url: "MarketingCustomers/CleanData/{systemSourceId}/{systemSourceCustomerId}/#customerErrorSection",
defaults: new { controller = "MarketingCustomers", action = "CleanData", systemSourceId = "", systemSourceCustomerId = "" }
);
发布于 2017-05-19 06:52:28
现在我已经接近了,下面的代码在视图中工作得很好,但是当我把它放在一个分部视图中时,它就不能再工作了。
<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>
https://stackoverflow.com/questions/44053538
复制