(使用MVC 2)
从我的控制器操作中,我需要显示网址:
/MyController/Show/123
如何使用帮助程序生成此URL?
答案 0 :(得分:1)
简单:
public ActionResult Show(int id )
{
var completeURL = Request.RawUrl;
var relativePath = Request.Path;
var uriObject = Request.Url;
}
来自其他控制器:
var url = Url.Action("Show", "MyController", new {id = 123});
但也许你只需要重定向?
public ActionResult Index()
{
return RedirectToAction("Show", "MyController", new {id = 123});
}