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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With