HTMLヘルパー ActionLinkHtml.ActionLink @Html.ActionLink(
"詳細", // リンク・テキスト
"Details", // アクション名
"Books", // コントローラ名
new { id = Model.Isbn }, // ルート・パラメータ
new { @class = "menu" } // そのほかの属性
)}
http://msdn.microsoft.com/ja-jp/library/dd504972(v=vs.108).aspx 匿名型で使えないキー名を指定するにはタグの属性のハイフンはアンダーバーに変換する<a data-val="foo">CLICK</a> ↓ @Html.ActionLink("Goto","Index","Home",null, new {data_val = "foo"})
http://www.itorian.com/2013/02/ajaxactionlink-and-htmlactionlink-in-mvc.html DictionaryもしくはRouteValueDictionaryを使う @Html.ActionLink("Edit", "edit", "markets",
new RouteValueDictionary { { "foo.bar.baz", "abc" } },
new Dictionary<string, object> { { "class", "ui-btn-right" }, { "data-icon", "gear" } });
クエリストリングではなくURLでIDを渡すViewでのActionLinkの使い方 @Html.ActionLink("ユーザ詳細", "detail", "user", new { id = Model.User_id }, null)
↓これで作成されるAタグ <a href="/user/detai/123">ユーザ詳細</a> ControllerでのURLパラメータの受け取り方 [HttpGet]
public ActionResult Detail(int user_id) { }
デフォルトのRouteConfig.cs routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
このような<a href="/user/detai/123">のIDの受け取り方は↑で指定されている。 動的なクエリパラメータを渡す @{
RouteValueDictionary tRVD = new RouteValueDictionary(ViewContext.RouteData.Values);
foreach (string key in Request.QueryString.Keys )
{
tRVD[key]=Request.QueryString[key].ToString();
}
}
@Html.ActionLink("Export to Excel", // link text
"Export", // action name
"GridPage", // controller name
tRVD,
new Dictionary<string, object> { { "class", "export" } }) // html attributes
http://stackoverflow.com/questions/6165700/add-query-string-as-route-value-dictionary-to-actionlink リファレンス
|
|