使用#重定向到页面中的div [英] Redirect to div in page with #

查看:111
本文介绍了使用#重定向到页面中的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在控制器中处理了一些数据后,我想重定向到网页的某个div.他们有什么方法可以在网址末尾添加#"吗?还是应该使用javascript处理它?<​​/p>

示例:

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

=>应该重定向到/Info/id = 4#item_55

解决方案

RedirectToAction具有

请注意,就像我上面所做的那样,您还需要将控制器指定为参数之一.

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.

这篇关于使用#重定向到页面中的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆