I want to redirect to a certain div of a webpage after handling some data in a controller. Is their any way to add the '#' to the end of the url? Or should I handle it with javascript?


public async Task<IActionResult> Edit(ViewModel model){
    return RedirectToAction("Info", new { id = model.Id, "#" = "item_55" });

=> Should redirect to /Info/id=4#item_55

  • instead of this, render the page normally i.e RedirectToAction and upon landing on that page in document.ready function use JQuery to scroll to appropriate section i.e # – Aarif Apr 18 at 8:29
  • 1
    @Aarif why use JavaScript and jQuery for something that’s natively supported by browsers? – bfontaine Apr 18 at 16:21

RedirectToAction has an overload that allows you to specify the fragment. Here's an example:

return RedirectToAction("Info", "Controller", new { id = model.Id }, "item_55");

Note that you also need to specify the controller as one of the arguments, as I've done above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.