剔除绑定对象问题

时间:2019-03-02 06:55:42

标签: typescript knockout.js

当我运行程序时,从控制器返回的值未显示在页面上。我使用了调试器,发现从控制器返回了值,但页面上没有任何显示。

enter image description here AboutController.cs

[HttpGet("[action]")]
public About AboutDetais()
{
    About about = new About();
    about.CompanyName = "Hashoo";
    about.Phone = "123455";

    return about;
}

public class About
{

    public string CompanyName { get; set; }
    public string Phone { get; set; }

}

about.ts

import * as ko from 'knockout';
import 'isomorphic-fetch';

interface AboutModel {
    companyName: string;
    phone: string;
}

class AboutPageViewModel {
    public aboutModel = ko.observable<AboutModel>();

    constructor() {

        fetch('api/About/AboutDetais')
            .then(response => response.json() as Promise<AboutModel>)
            .then(data => {
                this.aboutModel(data);
            });
    }
}

export default { viewModel: AboutPageViewModel, template: require('./about.html') };

about.html

<p>This is a simple example of a Knockout component</p>

<p>Company Namne: </p> <p data-bind="text: aboutModel.companyName"></p>
<p>Phone: </p> <p data-bind="text: aboutModel.phone"></p>

0 个答案:

没有答案