Add @onchange to Editorfor using Razor

Asked

Viewed 157 times

1

Hi, I’m trying to add @onchange to my EditorFor, Yeah, I’m gonna 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 this field in the function

you are in error. as it should be?

2 answers

3


Thus:

@Html.TextBoxFor(model => model.CEP, new { @class = "classe", onchange = "myfunction(id)" })
  • Thank you @Gypsy :)

2

Leaving this part to add directly to HtmlHelper you can do with jQuery. 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.