Я могу читать данные и отображать их на aurelia-SPA следующим образом:
В моем контроллере ASP.NET у меня есть:
[HttpGet("[action]")]
public IEnumerable<Team> Teams()
{
var Teams = _teamRepository.GetAllTeams().OrderBy(p => p.Name);
return Teams;
}
В файле машинописи страницы aurelia я могу затемчитать данные так:
@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;
});
}
А затем в html-файле страницы aurelia я могу показать данные примерно так:
<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>
Это работает отлично.Сейчас я не могу найти пример того, как создать простую форму и отправить данные из нее на контроллер ASP.NET.Например, если бы моя aurelia html содержала такую форму:
<form role="form" submit.delegate="postdata()">
<label for="name">Teamn Name</label>
<input type="text" value.bind="name" placeholder="Name">
<label for="teamurl">TeamUrl</label>
<input type="text" value.bind="teamurl" placeholder="Teamurl">
<button type="submit">Add Team to DB</button>
</form>