Khan Engineer
Khan Engineer

Reputation: 408

Angular Directives in Html helper

How to include Angular directives in Html Helper in ASP.NET MVC C#. I dont know how to include it. What I have done is following :

 @Html.EditorFor(model => model.Questions.Question , new{ng_model="quest"})
                    {{quest}}

But when I look for source code that does not have ng-model directive?

Upvotes: 0

Views: 3297

Answers (4)

Md Shahriar
Md Shahriar

Reputation: 2746

@Html.TextBox("Text1", null, new { ng_model = "model1" })

Upvotes: 0

Yogesh Sharma
Yogesh Sharma

Reputation: 227

We can do it very easily.

   @Html.EditorFor(model => model.Email, new { htmlAttributes = new { @ng_change = "call()" ,@class="form-control" }})

Upvotes: 0

Huguer Reyes
Huguer Reyes

Reputation: 1

To include Angular directives in Html Helper you should pass a null parameter as a second then pass the angular directive in a object.

@Html.DropDownList("ViewBag-Name", null, new { ng_model = "Model-Name"})

Where ViewBag-Name contains a SelectList object pass to the view from the controller.

Upvotes: 0

Andreas Dirnberger
Andreas Dirnberger

Reputation: 640

The second Argument of Html.EditorFor is for the extended ViewData. It is used by the template. The Default template dont use your additional entries. But it supports htmlAttributes

@Html.EditorFor(model => model.Questions.Question , new { htmlAttributes = new { ng_model="quest" }})

or render it with out any template

@Html.TextBoxFor(model => model.Questions.Question, new { ng_model = "quest" })

Upvotes: 2

Related Questions