如何从URL(ASP.NET MVC)中获取视图中的当前路由ID [英] How to get the current route ID within a View from the URL (ASP.NET MVC)

查看:57
本文介绍了如何从URL(ASP.NET MVC)中获取视图中的当前路由ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在从/Controller/Action/1之类的URL返回的视图中(假设控制器/action/id的默认路由),如何从视图内访问ID?

Within the view that is returned from a URL such as /Controller/Action/1 (assuming the default route of controller/action/id), how can I get access to the ID from within the View?

我不想在处理请求时将其添加到操作级别的ViewData字典中.

I don't want to have to add it to the ViewData dictionary at the action level when handling the request.

推荐答案

我认为这是您要寻找的:

I think this is what you're looking for:

<%=Url.RequestContext.RouteData.Values["id"]%>

这篇关于如何从URL(ASP.NET MVC)中获取视图中的当前路由ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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