Alert of ASP.NET objects in JS

0

Hi, I would like to know if I can do something like this in ASP.NET, because they know something like that I need to do, please do not eat me if it's a bad question, I see it more as a challenge: 3

 var idt = 2;
function detailTry(idt) {
  alert(
    '@Html.ActionLink("Check Request", "Details", "Request", new { id = idt })'
  );

}

It says that idt does not exist when I pass it, no matter what I do, in my case I get it from another function.

    
asked by E.Rawrdríguez.Ophanim 19.12.2017 в 19:21
source

1 answer

1

The content of the alert is a string for javascript whereas for razor it is a controller url, it only needs to assign that part to your idt that is mixed.

function detailTry(idt) {
  var cadena = '@Html.ActionLink("Check Request", "Details", "Request", new { id = "JSVar" })';
	cadena = cadena.replace("JSVar",idt);
  alert(cadena);
}
detailTry(2);

Example in MVC.Net

    
answered by 19.12.2017 / 19:23
source