【发布时间】:2017-06-22 03:43:11
【问题描述】:
我有一个简单的 ASP.NET Core Web 应用程序,其页面类似于 http://localhost:5050/Posts/Create/3。
在我的 Razor 视图 Views/Posts/Create.cshtml 中,我怎样才能获得值“3”以便我可以创建像 <a href="/Blogs/Details/3">« Back to Blog</a> 这样的链接?
到目前为止,使用以下 Tag Helper 创建了链接,但我不知道为asp-route-id 放什么:
<a asp-controller="Blogs" asp-action="Details" asp-route-id="" class="btn btn-default btn pull-right">« Back</a>
我只是使用默认的mvc路由:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
我知道我可以从模型中获取它(即Model.Blog.BlogId),但我希望使用Request.Query["id"] 中的Views/Post/Create.cshtml 中的Request.Query["id"] 从Url 中获取它。
我试过asp-route-id="@Context.Request.Query["id"]。
【问题讨论】:
标签: asp.net-core asp.net-core-mvc tag-helpers