Roberts Kalderauskis Roberts Kalderauskis - 2 years ago 90
AngularJS Question

Is there a way to pass string value to js file from View via function

I am trying to pass Model values from View to js via function. The problem is, i can pass integer, double values but not string. Is there a way to pass string to js via function?

Passing (cshtml file):

ng-submit="vm.updateProduct(@Model.Id, @Model.Name, @Model.Price)"

Receiving (js file):

vm.updateProduct = function (id, productName, productPrice)

Answer Source

Just add quotes around the string parameter. @Model.Name will only render the string value, so you need the quotes to make it valid javascript:

ng-submit="vm.updateProduct(@Model.Id, '@Model.Name', @Model.Price)"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download