我有一个页面,我想知道何时对任何字段进行了任何更改,然后我将禁用并启用保存按钮。
我正在使用下面的代码,它不起作用有人知道我缺少什么吗?
@using CirrusAdmin.Models
@model MedicineModel
@{
ViewBag.Title = "Update Medicine";
}
<script src="@Url.Content("~/Scripts/knockout-2.1.0.js")" type="text/javascript"></script>
<script type="text/javascript">
var initialData = @Html.Raw(Json.Encode(Model));
var viewModel = {
item : ko.observable(initialData),
isDirty : ko.DirtyFlag(item)
};
ko.applyBindings(viewModel);
</script>
<hgroup class="title">
<h1>@ViewBag.Title.</h1>
</hgroup>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary()
<fieldset>
<ol>
<li>
@Html.LabelFor(m => m.Code)
@Html.TextBoxFor(m => m.Code, new { data_bind= "value: Code", @readonly = "readonly" })
</li>
<li>
@Html.LabelFor(m => m.Name)
@Html.TextBoxFor(m => m.Name, new { data_bind = "value: Name" })
</li>
<li>
@Html.LabelFor(m => m.GenericName)
@Html.TextBoxFor(m => m.GenericName, new { data_bind = "value: GenericName" })
</li>
</ol>
</fieldset>
<input type="submit" data-bind="enable: isDirty" value="Save" />
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}