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

请您参考如下方法:

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

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

你需要使用 Ajax.BeginForm overload接受 htmlAttributes 之类的 this one :
<% using (Ajax.BeginForm( 
          "GetCalendar", // actionName 
          null, // routeValues 
          new AjaxOptions { UpdateTargetId = "siteRows" }, // ajaxOptions 
          new { data_bind="submit: save", @class="employeeListEditor" } // htmlAttributes 
         )) 
{%> 


评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!