href链接中的hash要发送到控制器

时间:2015-03-10 12:59:07

标签: javascript html asp.net-mvc

我有一个像下面的动作div

<div class="action">
    <a href="/sertanarig/calismalar/theschoolforgods#" class="grid-item-link"></a>
    <div class="top">
        <a href="#add-to-list-lightbox" class="fa fa-plus add-to-list" data-id="53431d26721730077443eee2" data-type="Work">
        </a>
        </div>
        <div class="bottom">
                <a href="/sertanarig/calismalar/theschoolforgods#">
                        <h4 class="grid-item-name">The School for Gods #1</h4>
                </a>
                <a href="" class="comments">
                        <i class="fa fa fa-comments-o"></i>
                </a>
        </div>
</div>

当点击/sertanarig/calismalar/theschoolofgods#时,它应该将theschoolofgods#作为参数发送给控制器,但它只是发送了schoolofgods,并且遗漏了哈希符号并且页面返回到顶部。我该如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

Hash parameters仅供客户端使用。

如果您希望在服务器端发送散列,则应对其进行编码。

<a href="/sertanarig/calismalar/theschoolforgods%23">

例如,您可以使用@Url.Encode

答案 1 :(得分:1)

你不应该使用#符号,因为它用于anchor系统(当前页面中存在的元素的参考)

我建议您对其进行编码,或使用其他符号