Add onblur event to ASP.Net MVC Html.TextBox

What is the correct syntax for the HTML helper (in MVC2) to define an onblur handler, where a text field is generated with code like:

<%=Html.TextBox( "ChooseOptions.AddCount" + order.ID, (order.Count > 0) ? AddCount.ToString() : "", new { @class = "{number: true} small-input" } ) 
+4
source share
1 answer

Add onblur to htmlattributes

 <%=Html.TextBox( "ChooseOptions.AddCount" + order.ID, (order.Count > 0) ? AddCount.ToString() : "", new { @class = "{number: true} small-input", onblur = "alert('fired')" } ) %> 

Or better add it using jQuery

 $('#ChooseOptions_AddCount' + id).onblur(function() { alert('fired'); }); 
+6
source

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


All Articles