加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-core – 如何从ASP.NET Core中的Razor View获取Url中的i

发布时间:2020-12-16 04:07:14 所属栏目:asp.Net 来源:网络整理
导读:我有一个简单的ASP.NET Core Web应用程序,其页面类似于http:// localhost:5050 / Posts / Create / 3. 在我的Razor View Views / Posts / Create.cshtml中,我如何能够获得值“3”,以便我可以创建类似 a href =“/ Blogs / Details / 3”?返回的链接博客 /
我有一个简单的ASP.NET Core Web应用程序,其页面类似于http:// localhost:5050 / Posts / Create / 3.

在我的Razor View Views / Posts / Create.cshtml中,我如何能够获得值“3”,以便我可以创建类似< a href =“/ Blogs / Details / 3”>?返回的链接博客< / A&GT ;?

到目前为止,使用以下Tag Helper创建了链接,但我不知道要为asp-route-id添加什么:

<a asp-controller="Blogs" asp-action="Details" asp-route-id="" class="btn btn-default btn pull-right">&laquo; Back</a>

我只是使用默认的mvc路由:

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "default",template: "{controller=Home}/{action=Index}/{id?}");
});

我知道我可以从模型中获取它(即Model.Blog.BlogId),但我希望使用Views / Post / Create.cshtml中的Request.Query [“id”]之类的东西从Url中获取它.

我试过asp-route-id =“@ Context.Request.Query [”id“].

解决方法

类似于Context.GetRouteData().Values [“id”]; ?

也是http://www.blakepell.com/how-to-get-the-current-route-in-a-view-with-asp-net-5-mvc-6

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读