1

我怎么能在模型或控制器中做这样的事情?

<%= Url.Action("Home"); %>
4

1 回答 1

3

您可以在控制器中使用Url属性:

public ActionResult Index()
{
    string url = Url.Action("Home");
    // Do something with the url
    return View();
}

就模型而言,您应该避免在那里使用此类方法。模型被传递给视图,视图可以访问可以完成这项工作的辅助方法。

于 2010-03-20T08:37:37.223 回答