【问题标题】:How can I put data attributes within an Ajax.BeginForm?如何在 Ajax.BeginForm 中放置数据属性?
【发布时间】:2012-10-16 18:54:23
【问题描述】:

因为我认为我使用的是 Knockout,所以我已经相应地设置了我的表单标签;

<form class="employeeListEditor" data-bind="submit: save">

但是,当我单击提交按钮时,我想做部分页面刷新。那么如何在 Ajax.BeginForm 中设置 data-bind 属性呢?

此语法无效;

<% using (Ajax.BeginForm("GetCalendar", new AjaxOptions { UpdateTargetId = "siteRows" }, new { data-bind="submit: save", class="employeeListEditor" }))
{%>

【问题讨论】:

    标签: asp.net-mvc knockout.js


    【解决方案1】:

    您需要在属性名称中使用 unserscore (_) 和 Ajax.BeginForm 帮助器(实际上所有 HTML 帮助器在给定的 htmlAttributes 对象参数中将 unserscore 替换为破折号)将自动将其替换为破折号( -)

    new { data_bind="submit: save", @class="employeeListEditor" }
    

    您需要使用Ajax.BeginForm overload,它接受像this one 这样的htmlAttributes:

    <% using (Ajax.BeginForm(
              "GetCalendar", // actionName
              null, // routeValues
              new AjaxOptions { UpdateTargetId = "siteRows" }, // ajaxOptions
              new { data_bind="submit: save", @class="employeeListEditor" } // htmlAttributes
             ))
    {%>
    

    【讨论】:

    • 谢谢。 null 必须存在才能使路由值起作用。
    猜你喜欢
    • 1970-01-01
    • 2015-05-22
    • 1970-01-01
    • 2023-02-09
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多