Razor mvc4将控件id添加到url-例如:http://myapp/mycontroller/myview#myanchorid

Razor mvc4将控件id添加到url-例如:http://myapp/mycontroller/myview#myanchorid,razor,asp.net-mvc-4,Razor,Asp.net Mvc 4,我的应用程序有一个包含许多部分的页面,当链接到应用程序中的其他页面时,需要大量滚动。是否有方法从调用页面上的actionlink请求传递url上的控件id?这将允许我直接滚动到目标页面上的该部分 我可能遗漏了一些明显的东西 这是我用来让它工作的助手 @helper Action(actionName As String, controllerName As String, fragment As String, routeValues As Object, displayText A

我的应用程序有一个包含许多部分的页面,当链接到应用程序中的其他页面时,需要大量滚动。是否有方法从调用页面上的actionlink请求传递url上的控件id?这将允许我直接滚动到目标页面上的该部分

我可能遗漏了一些明显的东西


这是我用来让它工作的助手

@helper  Action(actionName As String, controllerName As String, fragment As String, routeValues As Object,     displayText As String) 
     Dim url As New UrlHelper(HttpContext.Current.Request.RequestContext)
     Dim str As String = UrlHelper.GenerateUrl(routeName:=Nothing, actionName:=actionName, controllerName:=controllerName, routeValues:=New System.Web.Routing.RouteValueDictionary(routeValues), fragment:=fragment, protocol:=Nothing, _
hostName:=Nothing, routeCollection:=url.RouteCollection, requestContext:=url.RequestContext, includeImplicitMvcValues:=True)

     Dim outurl As String = String.Format("<a href=\'{0}\'>{1}</a>", str, displayText)

     @MvcHtmlString.Create(outurl)

End helper
@helper操作(actionName为字符串,controllerName为字符串,fragment为字符串,RouteValue为对象,displayText为字符串)
Dim url作为新的UrlHelper(HttpContext.Current.Request.RequestContext)
Dim str As String=UrlHelper.GenerateUrl(routeName:=Nothing,actionName:=actionName,controllerName:=controllerName,routeValues:=New System.Web.Routing.RouteValueDictionary(routeValues),fragment:=fragment,protocol:=Nothing_
主机名:=Nothing,routeCollection:=url.routeCollection,requestContext:=url.requestContext,includeImplicitMvcValues:=True)
Dim outurl为String=String.Format(“,str,displayText)
@MvcHtmlString.Create(outurl)
末端助手

在System.Web.Mvc名称空间中,您可以找到带有方法GenerateUrl()的类UrlHelper,在这里您可以使用片段参数构建您的url,该参数是您的控件id。

谢谢-将立即检查outall set-添加了解答