我认为您想要的是:
ASP.NET MVC1Html.Actionlink(article.Title, "Login", // <-- Controller Name. "Item", // <-- ActionMethod new { id = article.ArticleID }, // <-- Route arguments. null // <-- htmlArguments .. which are none. You need this value// otherwise you call the WRONG method ...// (refer to comments, below). )
这使用以下方法Actionlink签名:
ASP.NET MVC2public static string Actionlink(this HtmlHelper htmlHelper,string linkText, string controllerName, string actionName, object values,object htmlAttributes)
两个论点已经改变
Html.Actionlink(article.Title, "Item", // <-- ActionMethod "Login", // <-- Controller Name. new { id = article.ArticleID }, // <-- Route arguments. null // <-- htmlArguments .. which are none. You need this value// otherwise you call the WRONG method ...// (refer to comments, below). )
这使用以下方法Actionlink签名:
ASP.NET MVC3 +public static string Actionlink(this HtmlHelper htmlHelper,string linkText, string actionName, string controllerName, object values,object htmlAttributes)
参数与MVC2的顺序相同,但是不再需要id值:
Html.Actionlink(article.Title, "Item", // <-- ActionMethod "Login", // <-- Controller Name. new { article.ArticleID }, // <-- Route arguments. null // <-- htmlArguments .. which are none. You need this value// otherwise you call the WRONG method ...// (refer to comments, below). )
这样可以避免将任何路由逻辑硬编码到链接中。
<a href="/Item/Login/5">Title</a>
假定以下内容,这将为您提供以下html输出:
article.Title = "Title"
article.ArticleID = 5
- 您仍然定义了以下路线
。。
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)