1

在 MVC 中,我试图直接在 View 目录中链接到一个视图,该页面名为“Settings.cshtml”。我尝试了以下但没有成功:

@Html.ActionLink("Your Settings", "Settings", "View")
@Html.ActionLink("Your Settings", "Settings")
@Html.ActionLink("Your Settings", "Settings", "~/View")
4

1 回答 1

4

Action links do not link to a view, they link to an action. You will need to implement a controller action that returns the view:

public ActionResult Settings()
{
    return View();
}

If you place this in your HomeController, the following ActionLink should pick up your view:

@Html.ActionLink("Your Settings", "Settings")

If you need to do this a lot, you could look at implementing a more general Action method that allows you to pass in a view name, like so:

public ActionResult ShowView(string viewName)
{
    return View();
}

--

@Html.ActionLink("Your Settings", "ShowView", new { viewName = "Settings" })
于 2013-04-18T19:22:42.250 回答