이 코드가 있고 링크에 클래스를 추가하고 싶습니다. MVC3에서 이것을 할 수 있습니까?
Html.ActionLink("Create New", "Create")
답변
예, css 클래스를 나타내는 객체로 다른 매개 변수를 추가 할 수 있습니다.
Html.ActionLink("Create New", "Create", CONTROLLERNAME, null, new { @class= "yourCSSclass"} )
다음으로 번역 할 수 있습니다.
Html.ActionLink(link text, action name, controller name, route values object, html attributes object)
편집하다:
사용자 정의 스타일을 추가하려면 다음을 사용하십시오.
Html.ActionLink(
"Create New",
"Create",
CONTROLLERNAME,
null,
new { @class= "yourCSSclass", @style= "width:100px; color: red;" }
)
답변
@Html.ActionLink("ClickMe", // link text
"Index", // action name
"Home", // controller
new { id = 2131 }, // (optional) route values
new { @class = "someClass" }) // html attributes
답변
Html.ActionLink("Create New", "Create", null, htmlAttributes: new { @class = "className" })
답변
htmlAttributes 매개 변수를 사용하는 ActionLink 오버로드를 사용하여 생성 된 요소에 클래스를 추가 할 수 있습니다.
Html.ActionLink("Create New", "Create", new {}, new { @class = cssClass });
답변
문서 에 따르면 이것은 트릭을 수행합니다.
Html.ActionLink("LinkText", "Action", "Controller", new { }, new {@class="css class"})
편집 : Dampe에 주목 해 주셔서 감사합니다. 코드 샘플을 업데이트했습니다.
답변
