Html.EditFor Onchange Event

前端 未结 4 1724
南旧
南旧 2021-01-04 13:36

I am developing an MVC4 application.
I want to change IsChanged field in my Model, when model.ExternalVenderNo is changed.

Bel

相关标签:
4条回答
  • 2021-01-04 13:45

    try jquery for this

    $('#ExternalVenderNo').change(function(){
        alert('Changed!');
    });
    
    0 讨论(0)
  • 2021-01-04 13:51

    Try adding to attributes

    @Html.EditorFor(model => Model.Lengthofside1, new {  htmlAttributes = new { onchange = "OnChangeEvent(this)", @class = "form -control text-right" } })
    

    This worked for me.

    0 讨论(0)
  • 2021-01-04 13:53

    Try the same with @Html.TextBoxFor

    @Html.TextBoxFor(model => model.ExternalVenderNo, new { onchange = "OnChangeEvent()" })
    
    <script type="text/javascript">
     function OnChangeEvent(){
        alert("value is changed");
        @Model.IsChanged = true;
     }
    </script>
    

    or leave Jquery to handle the change event

    @Html.EditorFor(model => model.ExternalVenderNo)
    
    <script type="text/javascript">
    $('#ExternalVenderNo').change(function(){
        alert('Changed!');
        @Model.IsChanged = true;
    });
    </script>
    
    0 讨论(0)
  • 2021-01-04 14:05

    The following will definitely work for you.

    $(document).ready(function()
    {
       $('#ExternalVenderNo').on("change", function()
       {
          alert('Changed!');
       });
    });
    
    0 讨论(0)
提交回复
热议问题