Exception: Uncaught reference: Model is not defined – have you forgotten the ampersand?

In Aspnet MVC we use “Model” to send  data to the view/cshtml file.

Then we want to use this Model in Jquery.

One cannot simply write

$("#MyControl").text( Model.ID );

Instead write

$("#MyControl").text( "@Model.ID" );
I wouldn’t this either but instead send the data to a hidden control or something.  I can’t formalise why but the feeling is with me that I shouldn’t.
Read slightly more here and here.

Tags: ,

Leave a Reply