Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to div in page with #

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?

Example:

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

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

like image 236
Wouter Avatar asked Apr 18 '19 08:04

Wouter


1 Answers

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.

like image 92
Kirk Larkin Avatar answered Oct 23 '22 03:10

Kirk Larkin