我可以像这样读取数据并将其显示在aurelia-SPA上:
在我的ASP.NET控制器中,我有:
this.cancellablePromise
然后在aurelia页面打字稿文件上,我可以读取如下数据:
[HttpGet("[action]")]
public IEnumerable<Team> Teams()
{
var Teams = _teamRepository.GetAllTeams().OrderBy(p => p.Name);
return Teams;
}
然后在aurelia-page html文件中,我可以显示如下数据:
@inject(HttpClient)
export class Fetchdata {
public Teams: Teams[] | undefined;
constructor(http: HttpClient) {
http.fetch('api/SampleData/Teams')
.then(result => result.json() as Promise<Teams[]>)
.then(data => {
this.Teams = data;
});
}
这很好。现在,我找不到任何有关如何创建简单表单并将数据从表单发布到ASP.NET控制器的示例。例如,如果我的aurelia html包含这样的形式:
<template>
<h1>Teams in database</h1>
<p if.bind="!Teams"><em>Loading...</em></p>
<table if.bind="Teams" class="table">
<thead>
<tr>
<th>TeamName</th>
</tr>
</thead>
<tbody>
<tr repeat.for="team of Teams">
<td>${ team.name }</td>
</tr>
</tbody>
</table>
</template>
答案 0 :(得分:1)
在您的视图模型中,该模型与问题中具有相应表单的视图相对应-您需要实现postdata()
方法。假设视图模型已注入HttpClient
并分配给名为http
的属性以及在同一视图模型上声明的名为name
和teamurl
的属性,并且有一个名为{ {1}}的值就是您的发布端点的网址-postPath
方法看起来像这样:
postdata