How can I put data attributes in Ajax.BeginForm?

Since I use Knockout in my view, I set my form tag appropriately;

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

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

This syntax does not work;

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

You need to use unserscore ( _ ) in the name of your attribute, and the Ajax.BeginForm (in fact, all HTML helpers replace the unserscore dash in the specified parameters of the htmlAttributes object) will automatically replace its dash ( - )

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

And you need to use the 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 )) {%> 
+16
source

Source: https://habr.com/ru/post/1440021/


All Articles