Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我怎么能在模型或控制器中做这样的事情?
<%= Url.Action("Home"); %>
您可以在控制器中使用Url属性:
public ActionResult Index() { string url = Url.Action("Home"); // Do something with the url return View(); }
就模型而言,您应该避免在那里使用此类方法。模型被传递给视图,视图可以访问可以完成这项工作的辅助方法。