I'm learning C# and Asp.net for about 11 days with background in PHP and PHP related frameworks.
My problem is inserting Angular.js attributes like ng-controller
into Razor generated input elements.
The problem is this...
@Html.TextBoxFor(model => model.Name, new { @class = "Form__TextType Form__TextInput" })
So, this generates an html input[type=text]
element with a class attribute. This syntax does not support adding ng-model="someModel"
but I can do that with creating a Dictionary that has all the necessary attributes for that element on the server side and putting it as the last argument in TextBoxFor()
That way is not really good although it works. If i want to change an angular attribute, i would have to change the Dictionary object on the server side which could be very error prone.
Is there another way of adding angular attributes to Razor generated elements?
It seems that underscores in the HtmlAttributes parameters are converted to hyphens when rendering:
@Html.TextBoxFor(model => model.Name, new { ng_model="someModel" });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With