using javascript variable in MVC3 Razor view engine

后端 未结 2 643
天命终不由人
天命终不由人 2020-12-01 07:33

Is it possible?

@Html.ActionLink( \"Link text\", \"Action Name\", new { id = *JAVASCRIPT VARIABLE* })

Please explain with example code.

2条回答
  •  孤独总比滥情好
    2020-12-01 08:16

    It actually is very much possible with the following:

    var hello = "Great Job!";
    
    var text = "@Html.ActionLink( "Link text", "Action Name", new { id = "JSVar" })"
    text = text.replace("JSVar",hello);
    

    As easy as that! :)

    All the @Html.Action link does is create a url string so doing replace on it is the same as replace on any javascript string

提交回复
热议问题