如何将数据属性放入Ajax.BeginForm中?(How can I put data attributes within an Ajax.BeginForm?)

编程入门 行业动态 更新时间:2024-10-24 03:23:50
如何将数据属性放入Ajax.BeginForm中?(How can I put data attributes within an Ajax.BeginForm?)

因为我在视图中使用了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" })) {%>

Because I am using Knockout in my view, I have set my form tag accordingly;

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

However when I click the submit button, I want to do a partial page refresh. So how do I set the data-bind attribute in the Ajax.BeginForm?

This syntax does not work;

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

最满意答案

您需要在您的属性名称和Ajax.BeginForm助手中使用unserscore( _ )(事实上,所有HTML助手用给定htmlAttributes对象参数中的破折号替换unserscore)将自动用短划线( - )替换它,

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

你需要使用一个Ajax.BeginForm 重载 ,它接受像这样的 htmlAttributes:

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

You need to use unserscore (_) in your attribute name and the Ajax.BeginForm helper (in fact all the HTML helpers replaces unserscore with dashes in the given htmlAttributes object parameters) will be automatically replace it with a dash (-)

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

And you need use an Ajax.BeginForm overload which accepts htmlAttributes like this one:

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

更多推荐

本文发布于:2023-08-05 17:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437463.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   放入   属性   数据   Ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!