asp.net核心中的网址操作 [英] Url.Action in asp.net core

查看:47
本文介绍了asp.net核心中的网址操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢新的标记助手属性,这些属性使可读的动态html内容成为可能.我可以通过使用asp-controller和asp-action属性创建链接,如下所示:

I like the new tag helpers attributes which make readable dynamic html contents. I can create a link by using the asp-controller and asp-action attributes like this:

<a asp-controller="Home" asp-action="Index">Index</a>

问题是,在某些情况下,我只需要操作的URL即可使用我的JavaScript.例如,为了在ASP.NET MVC 5中进行ajax调用,我可以使用以下代码:

The problem is that there are cases where I need just the URL of the action in order to use it my javascript. For example in order to make an ajax call in ASP.NET MVC 5, I could have the following code:

$.ajax({
    type: "POST",
    url: '@Url.Action("GetData","Ajax")',
    data: "{ }",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
    }
});

我试图在ASP.NET Core中找到一个等效的方法,但是我找不到一个方法,因此必须自己创建URL.有没有一种方法可以在ASP.NET Core中获取操作"和剃刀页面" URL.

I tried to find an equivalent method in ASP.NET Core but I was not able to find one so I have to create the URL myself. Is there a way to get the Action and Razor Page URL in ASP.NET Core.

推荐答案

我刚刚找到了解决方法.如果有人在找同样的东西,这里是怎么做的.

I just found how to do it. In case someone else is looking for the same thing here is how to do it.

@this.Url.Action("Index", "Home")

这篇关于asp.net核心中的网址操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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