Html助手中的Angular指令

时间:2015-01-02 08:12:00

标签: c# html angularjs-directive razorengine

如何在{MVC C#中的Angular directives中包含Html Helper。 我不知道如何包含它。 我所做的是:

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

但是当我查找没有ng-model directive的源代码时?

4 个答案:

答案 0 :(得分:2)

Html.EditorFor的第二个参数用于扩展的ViewData。 它由模板使用。默认模板不使用您的其他条目。 但它支持htmlAttributes

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

或使用任何模板进行渲染

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

答案 1 :(得分:0)

要在Html Helper中包含Angular指令,您应该将null参数作为第二个传递,然后在对象中传递angular指令。

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

ViewBag-Name包含一个SelectList对象从控制器传递给视图。

答案 2 :(得分:0)

我们可以很容易地做到。

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

答案 3 :(得分:0)

@ Html.TextBox(“ Text1”,空,新的{ng_model =“ model1”})