At the end of my controller method, I am returning a view with a viewmodel
return View(viewModel);
This works fine and opens the corresponding view.
I now want to jump to an anchor which I normally can by adding #myanchor
to the URL. But I couldn't find a way to do this via the return View(...);
.
Is this somehow possible?
Thanks in advance
You can't do this using View(), however there is another solution. Create a viewbag just before, and assign it anchor value:
ViewBag.AnchorValue = "#myanchor";
return View(viewModel);
Then, in your front view
$(document).ready(function () {
var anchor = document.getElementById('@Viewbag.AnchorValue');
anchor.scrollIntoView(true);
});
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.