Asp.net mvc SPA淘汰JS过滤器

Asp.net mvc SPA淘汰JS过滤器,asp.net-mvc,knockout.js,single-page-application,Asp.net Mvc,Knockout.js,Single Page Application,我使用ADO.Net作为数据源开发了MVC4单页应用程序。尝试按ID筛选视图时,尝试了会话变量,但没有成功。以下是查看代码: <script type="text/javascript" src="@Url.Content("~/Scripts/BloodPressuresViewModel.js")"></script> <script type="text/javascript"> $(function () { upshot.me

我使用ADO.Net作为数据源开发了MVC4单页应用程序。尝试按ID筛选视图时,尝试了会话变量,但没有成功。以下是查看代码:

<script type="text/javascript" src="@Url.Content("~/Scripts/BloodPressuresViewModel.js")"></script>
<script type="text/javascript">
    $(function () {
        upshot.metadata(@(Html.Metadata<KOTest2.Controllers.DALController>()));

        var viewModel = new MyApp.BloodPressuresViewModel({
            serviceUrl: "@Url.Content("~/api/DAL")"
        });
        ko.applyBindings(viewModel);
    });
</script>
我认为最好的解决方案是使用ViewBag将ID从控制器传递到视图。知道我该怎么做吗

由于我不是经验丰富的程序员,是否可以过滤(foreach)



提前感谢。

我不知道您是如何访问数据库(在服务器上,对吗?)进行筛选的,但您可以这样做:

<table data-bind="foreach: rows">
    <tr>
        <td>id: <span data-bind="text: ID"></span></td>
        <td>PHN: <span data-bind="text: PHN"></span></td>
        ....
    </tr>
</table>

无论您如何进行身份验证,在验证成功后,执行
this.loggedIn(true)
,这将导致计算函数触发从服务器的拉取和
this.rows()的设置;这反过来会更新显示。

不清楚您想做什么。你想过滤什么?看起来页面上已经有了ID。ID在类中,我需要在用户登录时使用ID筛选数据库。谢谢
 <tbody data-bind="foreach: bloodPressures">
<table data-bind="foreach: rows">
    <tr>
        <td>id: <span data-bind="text: ID"></span></td>
        <td>PHN: <span data-bind="text: PHN"></span></td>
        ....
    </tr>
</table>
function viewModel() {
    var self = this;
    this.loggedIn = ko.observable(false);
    this.rows = ko.observableArray([]);

    // return an array of objects to display to the user
    function getDataFromServer() {

         return ...;
    }

    ko.computed(function() {
        if (this.loggedIn())
            this.rows(getDataFromServer());
    },this);

    ...
}