How to anchor a redirect in APS.NET MVC

Asked

Viewed 338 times

1

How can I send the user to a certain block of the page by passing the id to the url. For example: http://getbootstrap.com/css/#type, how to pass this type in ASP.NET MVC using the return RedirectToAction.

The line of my code is like this: return RedirectToAction("Index", "Home");, tried return RedirectToAction("Index", "Home",new{#type}); but he won’t accept the "#".

And another question, what is the name of this resource where you pass the "#" in the page url.

3 answers

1


This feature is called Ancora, to perform on a redirect in MVC, instead of Redirecttoaction, follows the correct code line:

return Redirect(Url.Action("Index", "Home")+"#type");
  • Junio , did not work, is returning this page: https://prnt.sc/fmupc6

  • Junior I fixed the line you gave me, it worked ! what was giving problem was the "/" of "/#type";

  • @Leonardobonetti, I really had forgotten the "/" I will edit the question, vlw.

  • actually I had edited, the correct is without bar :D

0

Just use HTML anyway, do so:

The link:

<a href="#idDoElemento">Meu link teste</a>

His element

<p id="idDoElemento">teste</p>

i.e., in the link, type # + the id of the element you want the link to point to.

It’s called an anchor

  • 1

    The element in HTML is called "anchor" (originally had to use a tag <a name="abc">, the part of the URL that starts with # is called "fragment".

0

This feature is called anchor in HTML. You need to create the anchor and then just call it on any link.

Creating the anchor:

<a name="NOME_DA_ANCORA"></a> 

Going to the anchor:

<a href="#NOME_DA_ANCORA">Ir para topo!</a> 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.