因为我在视图中使用了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 )) {%>更多推荐
发布评论