Nimrod Yanai Nimrod Yanai - 1 month ago 4x
HTML Question

MVC razor return confirm variable

I have written this small piece of razor code with java script:

@Html.ActionLink("ערוך", "Edit", new { id = }) |
@Html.ActionLink("הצג פרטים מלאים", "Details", new { tz = }) |
var shem = ("האם אתה בטוח שברצונך למחוק את" + @Html.ValueFor(model => item.fname) + " " + @Html.ValueFor(model => item.lname) + "?");
@Html.ActionLink("מחק", "Delete", new { id = }, htmlAttributes: new { onclick = "return confirm('shem');"} )

All I want is for the variable to be displayed in the "return confirm," but for some reason it doesn't recognize that as a variable and will only write it down literally.

Things I've tried so far:

  1. Putting the while variable in the "return confirm" and avoid using a variable completely.

  2. Putting the name of the variable with an @ in front of it.

  3. removing the whole thing from the @{} (which caused the whole variable line to be rendered as a in the HTML page).

  4. Removing the '' around the variable's name in the "return confirm."

So what am I doing wrong? I'm sure it'll end up being a small syntax thing, but I just can't figure it out...


Try like this:

onclick = "return confirm(" + Json.Encode(shem) + ");"