在ASP.NET.MVC下的Bootstrap中的Html控件标签中使用模式

时间:2016-07-20 19:32:26

标签: asp.net-mvc twitter-bootstrap bootstrap-modal

我试图将一个模式合并到一个强制性的用户创建菜单中 使用模型属性通过

注册从模型显示到UI的框
 @Html.LabelFor(model => model.Address2, htmlAttributes: new { @class = "control-label col-md-2" })

命令。我想在模式上添加一个鼠标到字段,这样用户就知道在错过字段之前必须填写字段,如果框保留为空则获取验证错误。我想使用这样的东西,但我不知道如何将它合并到@html标签分配中。

            <a href="#" title="Address2" data-toggle="popover" data-placement="right" data-trigger="hover" data-content="This Field is required">address2</a> 

2 个答案:

答案 0 :(得分:0)

您只需添加启用弹出窗口所需的相关数据属性。 LabelFor辅助方法的第二个参数接受html属性的匿名对象。确保在那里传递数据属性。

@Html.LabelFor(model => model.Address2, new { @class = "control-label col-md-2", 
                                              data_toggle = "popover", 
                                              data_placement = "left", 
                                              data_trigger = "hover", 
                                              title = "Address2 is mandatory" })

要记住的一件事是,要为数据属性构建标记,在将htmlAttributes传递给helper方法时,需要将-替换为_,这意味着要获取输出{{ 1}},你应该通过"data-toggle"

还要确保通过调用元素上的"data_toggle"方法启用了弹出框功能

popover()

答案 1 :(得分:0)

<div class="form-group">
        @Html.LabelFor(model => model.Address2, htmlAttributes: new {@class ="control-label col-md-2",
        data_toogle= "popover",
        data_placement = "right",
        data_trigger = "hover",
        title = "Address2 is mandatory"
        })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Address2)
            @Html.ValidationMessageFor(model => model.Address2)

         </div>
     </div>

上面的代码只是显示控件标签,但它没有弹出功能。该脚本是正文后面的第一个脚本,完全按照指示的方式。

相关问题