目标:
在URL中表示“#”而不是“%23”,然后它应显示基于id的特定信息。
http://localhost:49332/Home/about2?a=1&b=2&actiona=#cs
http://localhost:49332/Home/about2?a=1&b=2&actiona=%23cs
问题:
我需要#的原因是根据html的id
当我在网址中使用“#cs”(http://localhost:49332/Home/about2?a=1&b=2&actiona=#cs)进行硬编码时,一切都运行良好。
单击超链接“测试链接”后,我不知道如何显示解码URL以显示“#”。
About.cshtml
@{
ViewBag.Title = "About";
}
<hgroup class="title">
<h1>@ViewBag.Title.</h1>
<h2>@ViewBag.Message</h2>
</hgroup>
<article>
<p>
Use this area to provide additional information.
</p>
<p>
Use this area to provide additional information.
</p>
<p>
Use this area to provide additional information.
</p>
<a href="@Url.Action("about2",
new { a=1, b=2, actiona="#cs"
})">
Test länk
</a>
</article>
<aside>
<h3>Aside Title</h3>
<p>
Use this area to provide additional information.
</p>
<ul>
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</aside>
About2.cshtml
@{
ViewBag.Title = "About2";
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.css" rel="stylesheet" />
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script>
jQuery(document).ready(function() {
var url = document.location.toString();
if ( url.match('#') ) {
var hash = url.split('#')[1];
// collapse the expanded panel
$('#accordion .accordion-collapse').removeClass('in');
// expand the requested panel
$('#' + hash + '_c').addClass('in');
setTimeout(function () {
window.scrollBy(0, -10);
}, 0);
}
});
</script>
<h2>About2</h2>
a<br> a<br> a<br> a<br> a<br> a<br> a<br> a<br> a<br> a<br> a<br> a<br> a<br> a<br> a<br> a<br> a<br> a<br> a<br>
<div id="accordion" class="accordion-group">
<div class="panel">
<h4 id="cs" class="accordion-title"><a data-toggle="collapse" data-parent="#accordion" data-target="#cs_c">Child Survival: Boosting Immunity and Managing Diarrhoea</a></h4>
<div id="cs_c" class="accordion-collapse collapse in">
<p>...</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
<p>aaaaa</p>
</div>
<h4 id="chgd" class="accordion-title"><a data-toggle="collapse" data-parent="#accordion" data-target="#chgd_c">Child Health, Growth and Development: Preventing Mental Impairment with Iodine and Iron</a></h4>
<div id="chgd_c" class="accordion-collapse collapse">
<p>...</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
<p>bbbbb</p>
</div>
<h4 id="wmnh" class="accordion-title"><a data-toggle="collapse" data-parent="#accordion" data-target="#wmnh_c">Women’s and Newborn Survival and Health: Iron Supplementation and Food Fortification</a></h4>
<div id="wmnh_c" class="accordion-collapse collapse">
<p>...</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
<p>ccccc</p>
</div>
</div>
</div>
public ActionResult About2(int? a, int? b, string actiona)
{
var genres = new List<Genre>
{
new Genre { Name = "album"},
new Genre { Name = "one"},
new Genre { Name = "two"}
};
return View("About2", genres);
}
答案 0 :(得分:0)
谢谢Stephen Muecke的帮助!
你不能拥有一个带有'#`的路线值。 #是一个片段 标识符。 - 使用@ Html.ActionLink(“Testlänk”,“about2”,“Home”, null,null,“cs”,new {a = 1,b = 2},null)并删除actiona 该方法的参数。