通过ASP.NET MVC机制链接到页面的位置(#ID)吗? [英] Linking to location on page (#id) through ASP.NET MVC mechanisms?
问题描述
我的例子:
我有一个查看
是presents一组具有从数据模型填充内容div标签。
I have a View
that presents a set of div tags that has content populated from the datamodel.
[这些海报,用不同的LOCATION_ID,自然]
[Multiple of these, with different location_id, naturally]
<div>
<a name="location_id"></a>
Content
</div>
现在,我有一个表格[在它自己的看法]认为提交的内容,增加了另一个记录到数据模型。一旦记录被创建和提交,我重定向回动作
,与<$ C $返回查看
C>&LT; DIV&GT; 房源
Now, I have a form [in its own view] that submits content that adds another record to the datamodel. Once the record is create and submitted, I redirect back to the Action
that returns the View
with the <div>
listing.
我的挑战是:
我想页面聚焦&LT; DIV&GT;
刚创建的块。理想情况下,我想做到这一点不使用JavaScript, - 我想用结束的URL的#location_id。
像这样:的http://网站/控制器/动作/编号:12
(或类似的规定)
I'd like the page to focus the <div>
block that was just created. Ideally I'd like to do this without the use of javascript, - I'd like to use an #location_id ending to the URL.
Like so: http://site/Controller/Action/Id#12
(or something along those lines).
任何人有关于如何去这样做?
Anyone got any tips on how to go about doing this?
编辑:我不能使用控制器的重定向
方法(或任何涉及原始URL它需要通过<$ C进行路由。 $ C>控制器/动作或路线
机制)。
I cannot use the controller's Redirect
method (or anything involving a raw url. It needs to be routed either through Controller/Action
or Route
mechanisms).
推荐答案
对不起,浪费大家的时间......
Sorry for wasting everyone's time...
我只记得,你可以与其他字符文字不是'/',
I just remembered that you can separate route segments with other character literals than '/',
所以很自然我可以建立这样的路线:
so naturally I can build a route like this:
routes.MapRoute(
"MyRoute",
"{controller}/{action}/{id}#{locid}",
new { ... });
问题解决了。
这篇关于通过ASP.NET MVC机制链接到页面的位置(#ID)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!