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

9
  • 1
    Remove @class="info"from the 4th parameter and add new { @class="info" } in lieu of the 5th parameter Commented May 3, 2016 at 11:31
  • @StephenMuecke if i set @Html.ActionLink("link here", "Details", "Product", new { id = item.ProductId}) then generate this link localhost:18715/Home/Details?Length=7 why? would you tell me please Commented May 3, 2016 at 11:39
  • You did not add new { @class="info" } in lieu of null for the last parameter :) Commented May 3, 2016 at 11:43
  • @StephenMuecke would you prompt answer ? with check my update Section Commented May 3, 2016 at 11:48
  • 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) Commented May 3, 2016 at 12:03

2 Answers 2

2

You have to write hmtl attributes like this:

@Html.ActionLink("Click Here", "Details", "Product", new { id = item.ProductId }, new { @class = "info"})
Sign up to request clarification or add additional context in comments.

4 Comments

would you check my update section ? why it is not working and working
Maybe this can solve your problem: @Html.ActionLink("Click here", "Details", new { controller = "Product", id = item.ProductId }, new { @class = "info" })
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
This post explains why is Html.ActionLink generating "length=7". Hope this post will be useful for you: stackoverflow.com/a/4360565/3401842
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.