Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从操作中检索未修饰的操作名称_C#_Asp.net_Asp.net Core_Asp.net Core 3.1 - Fatal编程技术网

C# 从操作中检索未修饰的操作名称

C# 从操作中检索未修饰的操作名称,c#,asp.net,asp.net-core,asp.net-core-3.1,C#,Asp.net,Asp.net Core,Asp.net Core 3.1,我有一个行动方法: [Area("Waffles")] public class WafflesController : Controller { [HttpGet("/waffles/edit/{id?}", Name = nameof(EditView))] public IActionResult EditView( int id ) { ... return View(); } } 在其他视

我有一个行动方法:

[Area("Waffles")]
public class WafflesController : Controller
{
    [HttpGet("/waffles/edit/{id?}", Name = nameof(EditView))]
    public IActionResult EditView( int id ) {
        ...
        return View();
    }
}
在其他视图/操作中,我可以使用以下任一方法检索此文件的URL(
/waffles/edit
):

url = urlHelper.Action(nameof(WafflesController.EditView));

url = urlHelper.RouteUrl(nameof(WafflesController.EditView));
        
但是,在视图/操作本身内部,两个调用都返回URL和path参数,即在
http://me.com/waffles/edit/1234
两个
UrlHelper
方法都返回
“/waffles/edit/1234”
,是否有一种方法可以让我从其他地方返回
“/waffles/edit”

编辑

为了澄清,在从上述操作启动的视图中
urlHelper.RouteUrl(nameof(WafflesController.EditView))
返回路由URL及其
id
“/waffles/edit/1234”
我只需要字符串
/waffles/edit/

有没有办法让我只返回“/华夫饼/编辑”

要在url中隐藏id,可以使用ajax get和TempData来实现:

视图:

更新 我需要在视图中以字符串形式进行/waffles/edit(不带id)

请尝试以下代码:

 string url = "/waffles/edit/1234";
 url = url.Remove(url.Length - (url.Split('/')[3].ToString().Length + 1));

谢谢,但我认为有一个误解-这不是关于隐藏URL,我需要在视图中的字符串中
/waffles/edit
(没有
id
)。@Olmy,很抱歉我误解了你的意思,如果你只想拆分URL字符串,那么你可以使用
split
Remove
方法来实现,我已经更新了我的答复。
[HttpGet("/waffles/edit", Name = nameof(EditView))]
public IActionResult EditView(int? id)
{
    if (id == null && TempData["Data"] != null)
    {
        id = Convert.ToInt32(TempData["Data"]);
    }
    else
    {
        TempData["Data"] = id;
    }

    return View();
}
 string url = "/waffles/edit/1234";
 url = url.Remove(url.Length - (url.Split('/')[3].ToString().Length + 1));