1

I have a JavaScript file in which I need to generate an action link via Razor syntax. Here's my code so far.

@{
  int ID = @:cardId;
  @:row.insertCell(0).innerHTML = @Url.Action("Details", "Cards", new { Id = ID});
}

I want to nest my own text in the link. ie. <a>MyText</a> However, the Url.Action method is the only method I know of to create a link via Razor and I don't see an overload method that allows me to customize the text of the link.

1 Answer 1

1

You should use an Html.ActionLink here. It has an extra argument that lets you make the link text.

@{
  int ID = @:cardId;
  @:row.insertCell(0).innerHTML = @Html.ActionLink("MyText", "Details", "Cards", new { Id = ID }, null)
}

Further, I doubt Url.Action would've helped you here anyways since it doesn't generate <a href="some_url_here"></a>, it only generates some_url_here. Html.ActionLink generates the entire thing. You can read up on the difference between the two here.

Sign up to request clarification or add additional context in comments.

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.