在上一篇個人第一個FluentNHibernate例子的基礎上,咱們用上knockoutjshtml
1用nuget添加knockoutjs包json
2用nuget添加json.net包app
3..在Index.cshtml中添加ide
<script src="~/Scripts/knockout-3.4.0.js"></script>
4.添加script在table後面this
<script> function ViewModel(items) { var self = this; self.items = items; } var viewmodel = new ViewModel(@Html.HtmlConvertToJson(Model)); ko.applyBindings(viewmodel); </script>
5.修改Index.cshtmlspa
<thead> <tr> <th>@Html.DisplayNameFor(model => model.Name)</th> <th>@Html.DisplayNameFor(model => model.Age)</th> <th>@Html.DisplayNameFor(model => model.Description)</th> </tr> </thead> <tbody data-bind="foreach:items"> <tr> <td data-bind="text:Name"></td> <td data-bind="text:Age"></td> <td data-bind="text:Description"></td> <td><a data-bind="attr:{href:'@Url.Action("Edit")/'+Id}" class="btn btn-primary">Edit</a> <a data-bind="attr:{href:'@Url.Action("Delete")/'+Id}" class="btn btn-danger">Delete</a></td> </tr> </tbody>
結果:.net
完整代碼:code
連接: http://pan.baidu.com/s/1o88FxQ6htm
密碼: 74r7blog
這是一次knoutoutjs的嘗試,不對之處望你們指正