SoftwareDriven.SurveyJs.Blazor
1.1.0
See the version list below for details.
dotnet add package SoftwareDriven.SurveyJs.Blazor --version 1.1.0
NuGet\Install-Package SoftwareDriven.SurveyJs.Blazor -Version 1.1.0
<PackageReference Include="SoftwareDriven.SurveyJs.Blazor" Version="1.1.0" />
<PackageVersion Include="SoftwareDriven.SurveyJs.Blazor" Version="1.1.0" />
<PackageReference Include="SoftwareDriven.SurveyJs.Blazor" />
paket add SoftwareDriven.SurveyJs.Blazor --version 1.1.0
#r "nuget: SoftwareDriven.SurveyJs.Blazor, 1.1.0"
#:package SoftwareDriven.SurveyJs.Blazor@1.1.0
#addin nuget:?package=SoftwareDriven.SurveyJs.Blazor&version=1.1.0
#tool nuget:?package=SoftwareDriven.SurveyJs.Blazor&version=1.1.0
SoftwareDriven.SurveyJs.Blazor
A Blazor WebAssembly wrapper for SurveyJS — render
JSON-defined forms and surveys as a Blazor component. The SurveyJS JavaScript
and its theme CSS are shipped inside the package as a single minified bundle;
no separate npm install or <link> is required in your app.
Targets .NET 10 (net10.0).
Installation
dotnet add package SoftwareDriven.SurveyJs.Blazor
No script tag is required — the component loads its bundled JavaScript on demand via a dynamic import.
Usage
Add the namespace (e.g. in _Imports.razor):
@using SoftwareDriven.SurveyJs.Blazor
Place the SurveyHost component and pass a survey definition. Json accepts a
POCO, a JsonElement, or a JSON string — it is serialized to the SurveyJS
survey JSON format. OnComplete is raised with the answers as a JSON string
when the user finishes the survey. OnValueChanged is raised on every answer
change while the survey is being filled in — use it for progress logging or
auto-save. OnCurrentPageChanged reports page navigation on multi-page surveys.
Use Data to prefill answers (resume or review an existing response) and Mode
to render read-only (SurveyMode.Display). Call GetDataAsync() to snapshot the
current answers at any time — e.g. for auto-save — without waiting for completion.
Data, Mode, Theme and Locale also react to later changes, and @bind-Data
gives you two-way access to the answers (a JSON string).
<SurveyHost Json="surveyJson" OnValueChanged="HandleValueChanged" OnComplete="HandleComplete" />
@if (result is not null)
{
<pre>@result</pre>
}
@code {
private string? result;
private void HandleValueChanged(SurveyValueChange change)
=> Console.WriteLine($"{change.QuestionName} = {change.ValueJson}");
private readonly object surveyJson = new
{
title = "Short survey",
elements = new object[]
{
new { type = "text", name = "firstName", title = "What is your name?", isRequired = true },
new
{
type = "radiogroup",
name = "mood",
title = "How are you today?",
choices = new[] { "Good", "Neutral", "Bad" }
}
}
};
private void HandleComplete(string resultJson) => result = resultJson;
}
For the full survey JSON schema (question types, pages, validation, logic, theming) see the SurveyJS documentation.
Component reference
SurveyHost
Parameters
| Parameter | Type | Description |
|---|---|---|
Json |
object (required) |
Survey definition in SurveyJS JSON format (POCO, JsonElement, or string). A new instance rebuilds the survey. |
Data |
object? |
Answers to prefill (POCO, JsonElement, or JSON string). Target of @bind-Data. |
Mode |
SurveyMode |
Edit (default) or Display (read-only). |
Theme |
object? |
SurveyJS theme to apply (POCO, JsonElement, or JSON string). |
Locale |
string? |
Language of the built-in UI texts (e.g. "de"). |
Notification events
| Event | Type | Description |
|---|---|---|
OnValueChanged |
EventCallback<SurveyValueChange> |
Raised on every answer change during editing (progress logging / auto-save). |
OnCurrentPageChanged |
EventCallback<SurveyPageChange> |
Raised on page navigation in multi-page surveys. |
OnComplete |
EventCallback<string> |
Raised on completion with the answers as a JSON string. |
OnPartialSend |
EventCallback<string> |
Raised when incomplete results should be saved (multi-page) — persist to resume later. |
DataChanged |
EventCallback<object?> |
Backing callback for @bind-Data; carries the answers as a JSON string. |
Veto / validation callbacks (synchronous, return a value — require Blazor WebAssembly)
| Callback | Type | Description |
|---|---|---|
OnCompleting |
Func<SurveyCompleting, bool>? |
Return false to prevent completion. |
OnPageChanging |
Func<SurveyPageChanging, bool>? |
Return false to keep the current page. |
OnValidateQuestion |
Func<SurveyQuestionValidation, string?>? |
Return an error message to mark a question invalid, or null if acceptable. |
Server-side hooks (async — wire to your own storage/validation, there is no built-in backend)
| Callback | Type | Description |
|---|---|---|
OnServerValidate |
Func<string, Task<IReadOnlyDictionary<string,string>?>>? |
Validate all answers (JSON in); return a map of question name → error message. |
OnUploadFiles |
Func<SurveyFileUpload, Task<IReadOnlyList<SurveyStoredFile>>>? |
Store uploaded files; return a stored reference per file. |
OnClearFiles |
Func<SurveyFileClear, Task<bool>>? |
Delete stored files; return true on success. |
Methods
| Method | Description |
|---|---|
ValueTask<string> GetDataAsync() |
Current answers as a JSON string ("{}" before first render). |
ValueTask SetDataAsync(object? data, bool merge) |
Replace (or merge) the answers. |
ValueTask<bool> NextPageAsync() / PrevPageAsync() |
Navigate pages; returns whether the page changed. |
ValueTask GoToPageAsync(int pageNo) |
Jump to the zero-based visible page index. |
ValueTask<bool> CompleteAsync() |
Complete the survey (validates the current page first). |
ValueTask ClearAsync(bool clearData, bool gotoFirstPage) |
Clear the answers. |
Context types
SurveyValueChange(QuestionName, ValueJson, DataJson)SurveyPageChange(PageName, PageNo, PageCount)SurveyCompleting(DataJson)SurveyPageChanging(FromPageName, ToPageName, DataJson)SurveyQuestionValidation(QuestionName, ValueJson)SurveyFileUpload(QuestionName, Files)withSurveyIncomingFile(Name, Type, ContentBase64)→ returnSurveyStoredFile(Name, Content)SurveyFileClear(QuestionName, FileName, ValueJson)
The component renders into its own container element and disposes the underlying SurveyJS instance when removed from the render tree.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.AspNetCore.Components.Web (>= 10.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.