views:

19

answers:

1

The following statement:

<%= Html.EditorFor(model => model.Material.Serial) %>

Generates the following code;

<div class="editor-field">  
    <input type="text" value="" name="Material.Serial" id="Material_Serial" class="input-validation-error">  
    <span id="Material_Serial_validationMessage" class="field-validation-error">Debe ingresar un serial</span>  
</div>

I want to add an onkeypress javascript attribute to my input through the EditorFor statement, I have tried to do the following:

<%= Html.EditorFor(model => model.Material.Serial, new{ onkeypress = "return disableEnterKey(event)"})%>

But this doesn't work.

+1  A: 

Its difficult to pass Additional attributes to EditorFor templates, but alternatively the same functionality could be implemented using jQuery or something similar:

$('#Material_Serial').keypress(function(event) {

  disableEnterKey(event);

});
James Connell