Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using @data-bind in ASP.NET MVC htmlAttributes throws exception

I am using ASP.NET MVC 3.0 and KnockoutJS. I was trying to add the binding into my View Helpers like this ...

@Html.TextBoxFor(model => model.Name, new { @placeholder = "Name", @size = "35", @data-bind = "value: aName" })

But this throws the exception ...

Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.

Can anyone enlighten me on what this means - and moreover, how to solve it?

like image 842
Ciel Avatar asked May 17 '11 15:05

Ciel


1 Answers

It doesn't like the hyphen in the property name. To fix this change @data-bind to @data_bind and this will then render with a hyphen on the page.

like image 77
Adam Flanagan Avatar answered Sep 21 '22 13:09

Adam Flanagan