Add @onchange in EditorFor using Razor

1

Hello, I'm trying to add @onchange to my EditorFor , so I'll have to add that field dynamically

CURRENT LINE

@Html.EditorFor(model => model.CEP, new { @class = "classe" }, new { @onchange = "myfunction(id)" } })

In my case, I would have another line of this, passing the id of that field in the

is in error. how should I stay?

    
asked by anonymous 10.12.2015 / 14:42

2 answers

3

So:

@Html.TextBoxFor(model => model.CEP, new { @class = "classe", onchange = "myfunction(id)" })
    
10.12.2015 / 14:49
2

Exiting this part of adding directly to HtmlHelper you can do with jQuery . It would look like this:

@Html.EditorFor(model => model.CEP, new { @class = "classe", id=ViewBag.Id })

<script>
      $('.classe').change(function () {
            var id = $(this).attr('id');
            alert(id);
        });
</script>
    
10.12.2015 / 14:55