锚链接和window.location之间的区别?
问题描述:
我有以下链接:锚链接和window.location之间的区别?
<a href='@Url.Action("MyAction","MyController", new SearchCriteriaAffaire { Page=3, PageSize=5 }, null)'>Test1</a>
该链接的作品。我在我的操作页面中收到了我的搜索条件。
现在,我有按钮下面的javascript:
<button id="buttonTest2">Test2</button>
<script language="javascript">
$("#buttonTest2").click(function() {
document.location = '@Url.Action("MyAction","MyController", new SearchCriteriaAffaire { Page=3, PageSize=5 }, null)';
});
</script>
此按钮所行的工作。我的意思是,我的行动页面没有收到我的搜索条件,我不知道为什么?
这让我疯狂!
的Test1和Test2的产生完全相同的网址(我在“查看源代码”检查通过右键单击HTML页面上):
/?SortBy=None&Page=3&PageSize=5'
任何帮助将不胜感激。
答
试试这个:
<button id="buttonTest2">Test2</button>
<script language="javascript">
$("#buttonTest2").click(function() {
document.location = '@Html.Raw(Url.Action("MyAction","MyController", new SearchCriteriaAffaire { Page=3, PageSize=5 }, null))';
});
</script>
耶!谢谢。为什么我需要使用这个?我无法看到“查看源代码”中的差异。 – Bronzato 2011-04-30 15:09:23
在html代码中隐式html编码应用于'&'替换为&,但不在锚的href中,因此它始终使用网址.. – 2011-04-30 15:13:05