C#Razor Forms - 插入角度属性

Mar*_*nda 3 asp.net-mvc razor angularjs

我正在学习C#和Asp.net大约11天,有PHP和PHP相关框架的背景知识.

我的问题是将Angular.js属性插入ng-controller到Razor生成的输入元素中.

问题是这个......

@Html.TextBoxFor(model => model.Name, new { @class = "Form__TextType  Form__TextInput" })
Run Code Online (Sandbox Code Playgroud)

因此,这会生成一个input[type=text]带有class属性的html 元素.这种语法不支持添加,ng-model="someModel"但我可以创建一个Dictionary,它在服务器端具有该元素的所有必要属性,并将其作为最后一个参数.TextBoxFor()

这种方式并不是很好,尽管它有效.如果我想更改agular属性,我将不得不更改服务器端的Dictionary对象,这可能非常容易出错.

是否有另一种方法可以为Razor生成的元素添加角度属性?

Kut*_*yel 5

在渲染时,HtmlAttributes参数中的下划线似乎会转换为连字符:

@Html.TextBoxFor(model => model.Name, new { ng_model="someModel" });
Run Code Online (Sandbox Code Playgroud)