Using angular attributes with TextBoxFor in ASP.NET MVC

I am using ASP.NET MVC with AngularJs. I am new to AngularJs, I am trying to create a form that uses angularjs.

So, for starters, I have a login form that asks for a username and password.

Username using Html.TextBoxFor as below

 @Html.TextBoxFor(m => m.UserName, new { ng-model="user.name" }) 

But the ideal shows ng-model as a red mistake. and gives an error on startup with this change.

Error message

account / login - c: \ SVN HOME \ ABC-SelfServe \ src \ ABC \ Web \ Views \ Account \ Login.cshtml (23): error CS0746: Invalid member declarator of anonymous type. Members of an anonymous type must be declared with the appointment of members, a simple name, or access to a member.

Until now, when I had to include html attributes, I did it this way and it worked. What syntax did I use to include the ng-.... angular attributes with a TextBoxFor razor?

+6
source share
1 answer

- in new { ng-model="user.name" } invalid C #. Change it to ng_model and MVC converts the underscore to a dash in the output.

+19
source

All Articles