Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 4 Razor - Naming javascript functions dynamically

I am trying to create the name of a function dynamically:

I set the name in razor code:

 @ { name="bob"; }

Then I try to create the javascript function, but the syntax is wrong.

function @name@:_onActivate() {
   .....
}

How can I use @name in the name of the function?

like image 844
Ian Vink Avatar asked Dec 08 '22 12:12

Ian Vink


1 Answers

I know im late to the party, but i had the same question and came up with this..

Use the @() Razor syntax:

function @(Model.Name)_Init() { .....some code... }

Works like a charm

(http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/)

like image 84
Remi Beaulieu Avatar answered Jan 05 '23 15:01

Remi Beaulieu