{"id":2495,"date":"2022-08-30T15:25:20","date_gmt":"2022-08-30T15:25:20","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/27\/mvc-how-to-dynamically-set-class-in-html-actionlink-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:25:20","modified_gmt":"2022-08-30T15:25:20","slug":"mvc-how-to-dynamically-set-class-in-html-actionlink-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/mvc-how-to-dynamically-set-class-in-html-actionlink-collection-of-common-programming-errors\/","title":{"rendered":"MVC &#8211; How to dynamically set @class in Html.ActionLink-Collection of common programming errors"},"content":{"rendered":"<p>Assuming you want &#8220;class&#8221; to be an HTML attribute and &#8220;PageIndex&#8221; to be an action parameter you can do this instead:<\/p>\n<pre><code>Pricing\n<\/code><\/pre>\n<p>MUSEFAN EDIT:<\/p>\n<p>You can still use an ActionLink like this&#8230;<\/p>\n<pre><code>@Html.ActionLink(\"Pricing\", \"Index\", \"Pricing\", new {PageIndex = 2}, new {@class = ViewBag.PageIndex == 2 ? \"\" : \"ActiveMenuItem\"})\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2014-01-27 08:37:30. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Assuming you want &#8220;class&#8221; to be an HTML attribute and &#8220;PageIndex&#8221; to be an action parameter you can do this instead: Pricing MUSEFAN EDIT: You can still use an ActionLink like this&#8230; @Html.ActionLink(&#8220;Pricing&#8221;, &#8220;Index&#8221;, &#8220;Pricing&#8221;, new {PageIndex = 2}, new {@class = ViewBag.PageIndex == 2 ? &#8220;&#8221; : &#8220;ActiveMenuItem&#8221;}) Originally posted 2014-01-27 08:37:30.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2495","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2495"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2495\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}