简体   繁体   中英

Preventing URL encoding in links

I am working with an MVC web app. My Home/Index page displays a table through a series of AJAX calls from dropdown lists and button presses. I currently have it set up to store what links are being chosen in location.hash . On loading the page it looks in location.hash and calls the appropriate functions to recreate the page as intended. I have links working like http://localhost:xxxxx/Home/Index#1 .

My 2 questions: A: On a separate page I am trying to link back to this page with @Html.ActionLink("Cancel", "Home/Index#1") . Unfortunately the URL gets encoded to http://localhost:xxxxx/text/Home/Index%231 causing it to not work. How can I prevent this and get the proper URL to be passed?

B: I am trying to get my submit to link to a specific spot on my index page. <button type="submit">Submit</button> . Where and how would I add a link to get the submit to take me to http://localhost:xxxxx/Home/Index#1 rather than http://localhost:xxxxx/Home/Index ?

I know asking two questions isn't good, but I thought these were similar and related enough to be okay. Any information on either or both is appreciated.

A: The URL gets encoded automatically with HTML helpers that I found. I instead just used <a href="~/Home/Index#1">Cancel</a> . It's not quite as fancy, but works.

B: My problem was in my controller. I send my data back to the controller to handle and then transfer to index from there. I was using a RedirectToAction, but again it encodes. return Redirect("~/Home/Index#1"); seems to be working.

If there are obvious problems with these solutions, please share. Otherwise at the moment, this seems to be the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM