0

Action link @class="info" not working for css

@Html.ActionLink("Click Here", "Details", "Product", new { id = item.ProductId, @class="info" },null)

Html page source

  <a href="/Product/Details/14?class=info">Click Here</a>

Update:

on the other hand

if i set @Html.ActionLink("link here", "Details", "Product", new { id = item.ProductId}) then generate this link localhost:18715/Home/Details?Length=7 why? and it is not working

if i set @Html.ActionLink("link here", "Details", "Product", new { id = item.ProductId},null)

it is working perfectly generate this link http://localhost:18715/Product/Details/17

what i am missing for each link

Nazmul Hasan
  • 10,130
  • 7
  • 50
  • 73
  • 1
    Remove `@class="info"`from the 4th parameter and add `new { @class="info" }` in lieu of the 5th parameter –  May 03 '16 at 11:31
  • @StephenMuecke if i set @Html.ActionLink("link here", "Details", "Product", new { id = item.ProductId}) then generate this link http://localhost:18715/Home/Details?Length=7 why? would you tell me please – Nazmul Hasan May 03 '16 at 11:39
  • You did not add `new { @class="info" }` in lieu of `null` for the last parameter :) –  May 03 '16 at 11:43
  • @StephenMuecke would you prompt answer ? with check my update Section – Nazmul Hasan May 03 '16 at 11:48
  • Maybe this can solve your problem: @Html.ActionLink("Click here", "Details", new { controller = "Product", id = item.ProductId }, new { @class = "info" }) – kkakkurt May 03 '16 at 11:49
  • @NazmulHasan, The answer by kkakkurt is correct. What is not working for you? –  May 03 '16 at 11:56
  • yes answer is correct ,if i want to do without @class = "info" then @Html.ActionLink("link here", "Details", "Product", new { id = item.ProductId}) but why generate this link localhost:18715/Home/Details?Length=7 – Nazmul Hasan May 03 '16 at 11:58
  • 2
    Because you still need the last `null` parameter, other wise `"Product"` is added as a route parameter and a `string` has only one property so it generates `length=7` because "Product" last a length of 7 (characters) –  May 03 '16 at 12:03
  • awesome! Thank you so much . – Nazmul Hasan May 03 '16 at 12:06

2 Answers2

2

You have to write hmtl attributes like this:

@Html.ActionLink("Click Here", "Details", "Product", new { id = item.ProductId }, new { @class = "info"})
kkakkurt
  • 2,790
  • 1
  • 30
  • 33
  • would you check my update section ? why it is not working and working – Nazmul Hasan May 03 '16 at 11:52
  • Maybe this can solve your problem: @Html.ActionLink("Click here", "Details", new { controller = "Product", id = item.ProductId }, new { @class = "info" }) – kkakkurt May 03 '16 at 11:54
  • yes answer is correct ,if i want to do without @class = "info" then @Html.ActionLink("link here", "Details", "Product", new { id = item.ProductId}) but why generate this link localhost:18715/Home/Details?Length=7 – Nazmul Hasan May 03 '16 at 12:02
  • This post explains why is Html.ActionLink generating "length=7". Hope this post will be useful for you: http://stackoverflow.com/a/4360565/3401842 – kkakkurt May 03 '16 at 12:06
0
  @Html.ActionLink("Back", "Index", " ", new { @class = "col-sm-3 btn btn-outline-secondary btnfs btn-sm" })

Here more than one CSS calls is attached to the for ActionLink. This is For Asp.net MVC

d219
  • 2,707
  • 5
  • 31
  • 36
R J
  • 475
  • 3
  • 14