Located at dustinkingen.github.io/SpaServices
Kingensoft.AspNetCore.SpaServices.TagHelpers is a NuGet library that contains tag helpers for building single-page applications on ASP.NET Core.
<application-state initial-state="@YourState">Example usage:
Index.cshtml
@page
@model IndexModel
<form id="app">
{{ message }}
</form>
@section Scripts
{
<application-state initial-state="@Model">
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: window.__INITIAL_STATE__
});
</script>
}Index.cshtml.cs
// Opt in to capture members to output
[JsonObject(MemberSerialization.OptIn)]
public class IndexModel : PageModel
{
[JsonProperty]
public string Message { get; set; }
public void OnGet()
{
Message = "Hello Vue!";
}
}ApplicationStateTagHelper is useful for smaller application (e.g. Razor Pages). Nesting application state (partial views) is not currently supported.
Check out the samples.