SoftwareDriven.SurveyJs.Blazor 2.0.1

dotnet add package SoftwareDriven.SurveyJs.Blazor --version 2.0.1
                    
NuGet\Install-Package SoftwareDriven.SurveyJs.Blazor -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SoftwareDriven.SurveyJs.Blazor" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SoftwareDriven.SurveyJs.Blazor" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="SoftwareDriven.SurveyJs.Blazor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SoftwareDriven.SurveyJs.Blazor --version 2.0.1
                    
#r "nuget: SoftwareDriven.SurveyJs.Blazor, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SoftwareDriven.SurveyJs.Blazor@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SoftwareDriven.SurveyJs.Blazor&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=SoftwareDriven.SurveyJs.Blazor&version=2.0.1
                    
Install as a Cake Tool

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) and wraps SurveyJS 3.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.

Themes

Theme accepts the name of any theme shipped with SurveyJS, so you do not have to paste a theme JSON to change the look:

<SurveyHost Json="surveyJson" Theme="@("ContrastLight")" />

Names come from the SurveyJS theme catalog — DefaultLight, DefaultDark, SoftLight, ContrastLight, BorderlessLight, FlatLight, PlainLight, MonochromeLight, ThreeDimensionalLight, each also with a Dark and a Panelless variant. The catalog is fetched lazily, so it is downloaded only if you actually reference a theme by name. A theme POCO, JsonElement, or JSON string still works as before.

Upgrading from v2: several themes were renamed in SurveyJS 3.0 — SharpLight → ContrastLight, SharpDark → ContrastDark, DoubleBorderLight → DefaultLight, DoubleBorderDark → DefaultDark, LayeredLight/SolidLight → SoftLight, LayeredDark/SolidDark → SoftDark.

Validating a survey definition

SurveyJS 3.0 can validate a survey definition against its properties metadata — useful for definitions coming from the Survey Creator or an external source. Register the linter and inject it:

builder.Services.AddSurveyJsLinter();
@inject SurveyLinter Linter

@code {
    private async Task Validate()
    {
        var report = await Linter.LintAsync(surveyJson);

        if (!report.IsValid)
        {
            foreach (var finding in report.Findings)
                Console.WriteLine($"{finding.Severity} {finding.RuleId} at {finding.Path}: {finding.Message}");
        }
    }
}

LintAsync returns a SurveyLintResult with the Findings list plus ErrorCount, WarningCount, InfoCount and SuppressedCount; IsValid is true when there are no errors. Each SurveyLintFinding carries RuleId, Severity (Error, Warning, Info), Message, Path, and optionally ElementName, ElementType and Suggestion.

Pass SurveyJS lint options as the second argument to silence rules or to declare variables and functions the linter cannot see:

await Linter.LintAsync(surveyJson, new
{
    rules = new Dictionary<string, string> { ["no-empty-title"] = "off" },
    knownVariables = new[] { "userId" },
});

GetRulesAsync() lists every rule id with its default severity. The linter ships as its own bundle, downloaded on first use — apps that only render surveys never pay for it.

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: a built-in theme name (e.g. "DefaultLight"), or a theme 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.

SurveyLinter (register with AddSurveyJsLinter())

Method Description
Task<SurveyLintResult> LintAsync(object surveyJson, object? options) Validate a survey definition; returns findings and counts.
Task<IReadOnlyList<SurveyLintRule>> GetRulesAsync() List every lint rule id with its default severity.

Context types

  • SurveyValueChange(QuestionName, ValueJson, DataJson)
  • SurveyPageChange(PageName, PageNo, PageCount)
  • SurveyCompleting(DataJson)
  • SurveyPageChanging(FromPageName, ToPageName, DataJson)
  • SurveyQuestionValidation(QuestionName, ValueJson)
  • SurveyFileUpload(QuestionName, Files) with SurveyIncomingFile(Name, Type, ContentBase64) → return SurveyStoredFile(Name, Content)
  • SurveyFileClear(QuestionName, FileName, ValueJson)
  • SurveyLintResult(Findings, ErrorCount, WarningCount, InfoCount, SuppressedCount) with IsValid
  • SurveyLintFinding(RuleId, Severity, Message, Path, ElementName, ElementType, Suggestion)
  • SurveyLintRule(Id, DefaultSeverity)

The component renders into its own container element and disposes the underlying SurveyJS instance when removed from the render tree. Each instance gets its own element-id prefix, so several surveys can share a page without colliding DOM ids.

License

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 57 11/25/2026
2.0.0 165 9/3/2026
1.1.0 159 7/9/2026
1.0.0 140 7/8/2026