1

Here I have an view model

public class SimpleModel {
    public string Id { get; set; }
    public string Name { get; set; }
}

And I passing the my model value,

...
var myModel = new SimpleModel() {
    Id = "1234";
    Name = "Dean";
};
return View(..., myModel);

Here the problem I faced, I trying to passing the value to a javascript after pressing a button or link, but it fail to work, I doubt did my model contain the value and I double check by display it out, it seems it contain value.

Here the part of my code

...
<a href="javascript:functionA(@Model.Name)">Call Function</a>
<span>@Model.Name</span>
...

If I remove the @Model.Name parameter, it work perfectly. Is there way to fix this? or I did wrong on the part I passing the parameter.

Error I get is

Uncaught SyntaxError: Invalid or unexpected token

Any help to this will be appreciated and sorry if I explain the situation bad. Thanks.

Dean
  • 668
  • 12
  • 32

1 Answers1

0

dude, dont use ; when declaring, this is C# code and you should do it like this:

var myModel = new SimpleModel() {
    Id = "1234",
    Name = "Dean"
};

and i believe this is C# not a javascript, this is ASP.NET, you put in wrong tag

Hans Yulian
  • 1,080
  • 8
  • 26