开发者

Difference between anchor link & window.location?

开发者 https://www.devze.com 2023-03-01 14:00 出处:网络
I have the link below: <a href=\'@Url.Action(\"MyAction\",\"MyController\", new SearchCriteriaAffaire { Page=3, PageSize=5 }, null)\'>Test1</a>

I have the link below:

<a href='@Url.Action("MyAction","MyController", new SearchCriteriaAffaire { Page=3, PageSize=5 }, null)'>Test1</a>

This links works. I received my search criteria in my action page.

Now, I have the button with javascript below:

<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>

This button 开发者_运维百科doest' work. I mean, I didn't receive my search criteria in my action page and I don't know why??

It drives me crazy!

Test1 and Test2 produces exactly the same url (I check in 'view source code' by right clicking on the html page):

/?SortBy=None&amp;Page=3&amp;PageSize=5'

Any help will be greatly appreciated.


try this :

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消