我正在使用一個標準的MVC 3 Web項目,我寫了我的HTML在一個標準的HTML文件,然後複製/粘貼到_layout.cshtml文件。通過包含所有正確的RenderBody()和@ Html.Partial(「_ LogOnPartial」),頁面可以正常工作,但_LogOnPartial中的ActionLink不會呈現href。LogOnPartial呈現與空白href - MVC 3
Html.ActionLink("Log On", "LogOn", "Account")
會出來爲:
<a href="">Log On</a>
這是你得到的標準鏈接不變,當你啓動一個MVC 3 Web項目。
註冊的航線有:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Products",
"{controller}/{action}/{id}",
new {controller = "Products", action = "Index"});
routes.MapRoute(
"Newsletter",
"{controller}/{action}/{emailAddress}",
new { controller = "Newsletter", action = "Index" });
routes.MapRoute(
"Account",
"{controller}/{action}/{id}",
new { controller = "Account", action = "LogOn", id = UrlParameter.Optional });
}
我不明白爲什麼會這樣,但在Visual Studio它不強調這讓我覺得這是不正常看到的AccountController行動或控制器。任何人有任何想法?
只是爲了排除顯而易見的問題,您在'AccountController'中確實有一個'LogOn'動作,不是嗎? – 2011-04-19 14:07:45
是的,我願意。這是作爲默認軟件包的一部分。事實上,有一個LogOn和一個LogOn(HttpPost)以及一個LogOn.cshtml。 – John 2011-04-19 14:18:33