我正在开发一个MVC4应用程序.
当model.ExternalVenderNo被更改时,我想在我的模型中更改IsChanged字段.
@H_301_20@解决方法
当model.ExternalVenderNo被更改时,我想在我的模型中更改IsChanged字段.
<div class="editor-field"> @Html.EditorFor(model => model.ExternalVenderNo,new { @onchange = "OnChangeEvent();" }) @Html.ValidationMessageFor(model => model.ExternalVenderNo) </div>
和
function OnChangeEvent() { alert("value is changed"); @{ Model.IsChanged = true; } }
要检查是否正在调用OnChangeEvent,我会发出警报.
但警报也不起作用.
这意味着OnChangeEvent不会被称为.
当model.ExternalVenderNo被更改时,我只想将IsChanged字段更改为true.
模特有bool IsChanged
尝试使用@ Html.TextBoxFor
@Html.TextBoxFor(model => model.ExternalVenderNo,new { onchange = "OnChangeEvent()" }) <script type="text/javascript"> function OnChangeEvent(){ alert("value is changed"); @Model.IsChanged = true; } </script>
或者让Jquery处理更改事件
@Html.EditorFor(model => model.ExternalVenderNo) <script type="text/javascript"> $('#ExternalVenderNo').change(function(){ alert('Changed!'); @Model.IsChanged = true; }); </script>