个人第二个FluentNHibernate例子with Knockout

在上一篇个人第一个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>
ViewModel

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>
Index,cshtml

结果:.net

完整代码:code

连接: http://pan.baidu.com/s/1o88FxQ6htm

密码: 74r7blog

这是一次knoutoutjs的尝试,不对之处望你们指正

相关文章
相关标签/搜索