setting html link href attribute with jquery or javascript in mvc razor page

maqskywalker used Ask the Experts™
Hi experts,

I have a mvc 5 application using C#, Razor, jquery.

This is a followup to this ticket:¬ificationFollowed=208651180#a42592893

in my view on my table my link is set like this it works fine:

<a id="ReportLink" target="_blank" href="">@Html.DisplayFor(modelItem => item.EmployeeID)</a>

Because on click i want user to got to

<a id="ReportLink" target="_blank" href="">@Html.DisplayFor(modelItem => item.EmployeeID)</a>

Is there a way to set the href attribute to

Having a Javascript variable called firstpartofhref = "" and then set it in the href before the @razor tag something like this?

 href=" firstpartofhref + @item.EmployeeID"

can i just store this razor tag @item.EmployeeID in a javascript variable called secondpartofhref also?

and then set the href attribute something like this?

 href=" firstpartofhref + secondpartofhref"
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
The Razor engine does not parse Javascript files, only Razor views. You can setting the variables inside your Razor view.
For example,
  var YourVariable= '@item.EmployeeID';
// create link
var a = document.createElement('a');
var linkText = document.createTextNode("my title text");
a.title = "my title text";
a.href = "" + YourVariable;

Open in new window

There is no activity from author.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial