在ASP.NET MVC中将角度属性与TextBoxFor一起使用 [英] Using angular attributes with TextBoxFor in ASP.NET MVC
问题描述
我正在将ASP.NET MVC与AngularJs一起使用.我是AngularJs的新手,我正在尝试创建一个使用angularjs的表单.
I am using ASP.NET MVC with AngularJs. I am new to AngularJs, I am trying to create a form that uses angularjs.
所以首先,我有一个登录表单,要求输入用户名和密码.
So to start with I have a login form which asks for username and password.
使用Html.TextBoxFor
的用户名,如下所示
The username using Html.TextBoxFor
as shown below
@Html.TextBoxFor(m => m.UserName, new { ng-model="user.name" })
但是ide将ng-model
显示为红色错误.并在运行此更改时给出错误.
But the ide shows the ng-model
as an error in red. and gives an error when run with this change.
错误消息
帐户/登录-c:\ SVN HOME \ ABC-SelfServe \ src \ ABC \ Web \ Views \ Account \ Login.cshtml(23):错误CS0746:无效的匿名类型成员声明符.必须使用成员分配,简单名称或成员访问权限来声明匿名类型成员.
account/login - c:\SVN HOME\ABC-SelfServe\src\ABC\Web\Views\Account\Login.cshtml(23): error CS0746: Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.
现在直到每当我必须包含我曾经这样做的html属性并且它可以正常工作时.我曾经用哪种语法在剃须刀TextBoxFor
中包含ng-....
角度属性?
Till now whenever I had to include html attributes I used to do like this and it used to work. What syntax do I used to include ng-....
angular attributes with razor TextBoxFor
?
推荐答案
new { ng-model="user.name" }
中的-
是无效的C#.将其更改为ng_model
,MVC将在输出上将下划线转换为短划线.
The -
in new { ng-model="user.name" }
is not valid C#. Change it to ng_model
and MVC will convert the underscore to a dash on output.
这篇关于在ASP.NET MVC中将角度属性与TextBoxFor一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!