【问题标题】:Binding the MVC Form Helper to a Bootstrap modal将 MVC 表单助手绑定到引导模式
【发布时间】:2013-02-16 20:06:59
【问题描述】:

使用一系列 MVC 驱动的表单,我想利用传统的 '@using (Html.BeginForm(...' 方法生成客户端表单,这些表单将在基于 Bootstrap 的模式中呈现。 I've found a technique that binds the modal 到一个 ajax 请求/响应方案,其中表单是这样定义的:

 <form class="form-horizontal well" data-async data-target="#rating-modal" action="/some-endpoint" method="POST">

我了解如何插入类属性 (new { @class="example"}),但我没有找到展示如何处理“data-async”和“data-target=xxx”的示例。

想知道 Darin Dimitrov 对 this question 的回答是否部分满足了我的需求。或者我需要更好地理解 EditorTemplates as suggested here

【问题讨论】:

    标签: ajax twitter-bootstrap asp.net-mvc-4 modal-dialog


    【解决方案1】:

    就像上课一样:

    new { @class="example"}
    

    对于数据属性可以这样做:

    new { @class="example", data_target="#rating-modal"}
    

    data_target 当 razor 解释 htmlAttributes 参数时输出data-target

    【讨论】:

    • 非常感谢 - 但是没有右手值的“数据异步”呢?我试过 '..., new {data_async, data_target="#rating-modal"} // 错误当前上下文中不存在名称 'data_async' 和 new {data_async=null, data_target="#rating- modal"} 并得到类似的错误。尝试新的 {data_async="", data_target="#rating-modal"} 将呈现 data-async="" 但如果这不是它自己的一系列问题,我会感到惊讶。 --赞赏
    • 我认为new {data_async="true", data_target="#rating-modal"} 应该完成这项工作。 jsfiddle.net/9mQdH。无论值如何,JS 都只是要求名称为 data-async 的属性。
    猜你喜欢
    • 1970-01-01
    • 2012-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    • 2015-11-05
    • 2023-03-12
    相关资源
    最近更新 更多