SurveyBuilder 1.1.11

dotnet add package SurveyBuilder --version 1.1.11
                    
NuGet\Install-Package SurveyBuilder -Version 1.1.11
                    
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="SurveyBuilder" Version="1.1.11" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SurveyBuilder" Version="1.1.11" />
                    
Directory.Packages.props
<PackageReference Include="SurveyBuilder" />
                    
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 SurveyBuilder --version 1.1.11
                    
#r "nuget: SurveyBuilder, 1.1.11"
                    
#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 SurveyBuilder@1.1.11
                    
#: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=SurveyBuilder&version=1.1.11
                    
Install as a Cake Addin
#tool nuget:?package=SurveyBuilder&version=1.1.11
                    
Install as a Cake Tool

SurveyBuilder.Blazor

A lightweight, extensible survey/form builder for Blazor applications. Create, edit, and manage surveys with a structured model that serializes to JSON for easy storage and retrieval.

For more information visit: https://github.com/naykakashima/SurveyBuilder.Blazor

To access from GitHub Packages: https://github.com/naykakashima/SurveyBuilder.Blazor/pkgs/nuget/SurveyBuilder

Features

  • 🏗️ Build surveys programmatically or through UI
  • ✏️ Edit existing surveys
  • 👁️ Real-time preview of survey forms
  • 💾 JSON serialization/deserialization for easy storage
  • 📝 Support for multiple question types:
    • Single choice (radio buttons)
    • Multiple choice (checkboxes)
    • Open-ended (text input)
    • Opinion scales (sliders)
    • Likert scales
  • 🎨 Built with MudBlazor for a polished UI

Installation

Add the package via NuGet:

dotnet add package SurveyBuilder.Blazor

Or add directly to your .csproj file:

<PackageReference Include="SurveyBuilder.Blazor" Version="1.1.*" />

Core Concepts

Survey Structure

  • SurveyModel: The root container for your survey

    • Title and description
    • Collection of questions
  • SurveyQuestionModel: Defines individual questions

    • Question text
    • Question type
    • Options (for choice-based questions)
    • Required flag

Basic Usage

Creating a Survey

All you need to do to render the survey builder is to use the following code snippet:

<SurveyBuilder SurveyChanged="@OnSurveyChanged" />

As well as the import statements

@using SurveyBuilder.Models
@using SurveyBuilder.Services
@using SurveyBuilder.Components

Example Usage

<SurveyBuilder SurveyChanged="@OnSurveyChanged" />
<MudButton OnClick="SaveToDb" Color="Color.Primary" Class="mt-2">Save to DB</MudButton>

@code{

private Task OnSurveyChanged(SurveyModel survey)
    {
        CurrentSurvey = survey;
        Serialized = JsonService.Serialize(survey);
        return Task.CompletedTask;
    }



// Serialize to JSON
    private Task SaveToDb()
    {
        if (CurrentSurvey is null)
            return Task.CompletedTask;

        Console.WriteLine("Save triggered:");
        Console.WriteLine(Serialized);

        CurrentSurvey.Id = Guid.NewGuid().ToString();
        Repo.Add(CurrentSurvey);
        Nav.NavigateTo("/listsurveys");

        return Task.CompletedTask;
    }
}

Editing a Survey

The DemoApp provides an example of how persistence could be incorporated via parent-child parameter bind between editing and creating the surveys

<SurveyBuilderEditor Survey="Survey" SurveyChanged="OnSurveyChanged" />

@code{
	protected override void OnInitialized()
	{
		var loaded = Repo.GetById(Id);

		if (loaded is not null)
		{
			// Detach from repo to prevent accidental mutation
			Survey = JsonService.Deserialize(JsonService.Serialize(loaded));
		}
	}

	private Task OnSurveyChanged(SurveyModel updated)
	{
		Survey = updated;
		return Task.CompletedTask;
	}
}

Filling Up The Survey

A thorough decision has been made to not make filling the survey part of the package as it would result in dangerously high coupling and will significantly affect the freedom that the user will choose to do with the SurveyBuilder JSON.

As an alternative this is a highly reusable snippet taken from the DemoApp

<MudText Typo="Typo.h5">@Survey.Title</MudText>
<MudText Typo="Typo.subtitle2" Class="mb-4">@Survey.Description</MudText>



<MudStack Spacing="2">
    @foreach (var question in Survey.Questions)
    {
        @switch (question.Type)
        {
            case QuestionType.OpenEnded:
                <MudTextField T="string"
                Placeholder="Type your answer here..."
                Value="@GetString(question.Id)"
                ValueChanged="val => SetString(question.Id, val)"
                />
                break;


            case QuestionType.SingleChoice:
                <MudRadioGroup T="string"
                Value="@GetString(question.Id)"
                ValueChanged="@(val => SetString(question.Id, val))">
                    @foreach (var option in question.Options!)
                    {
                        <MudRadio T="string" Value="@option" Label="@option"/>
                    }
                </MudRadioGroup>
                break;

            case QuestionType.OpinionScale:
                <MudSlider Min="1" 
                           Max="10"
                           Value="@(GetNullableInt(question.Id) ?? 5)"
                           ValueChanged="@((int val) => SetAnswer(question.Id, val))"
                           Immediate="true"/>
                <MudText>Selected: @(GetNullableInt(question.Id) ?? 5)/10</MudText>
                break;

            case QuestionType.LikertScale:
                <MudRadioGroup T="string"
                              Value="@GetString(question.Id)"
                              ValueChanged="@(val => SetString(question.Id, val))">
                    @foreach (var option in question.Options!)
                    {
                        <MudRadio T="string" Value="@option" Label="@option"/>
                    }
                </MudRadioGroup>
                break;


            case QuestionType.MultiChoice:
                @foreach (var option in question.Options!)
                {
                    <MudCheckBox T="bool"
                                Label="@option"
                                Value="@(GetList(question.Id).Contains(option))"
                                ValueChanged="@((bool val) => OnMultiChoiceChanged(question.Id, option, val))"/>
                }
                break;
        }
    }
</MudStack>

<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="SubmitSurvey">Submit</MudButton>

Demo Application

The repository includes a sample Blazor application demonstrating:

  • Survey creation/editing interface
  • Survey preview functionality
  • JSON import/export
  • Survey response collection

To run the demo:

dotnet run --project samples/SurveyBuilder.DemoApp

Extending Functionality

  • Implement these interfaces for custom behavior:
    • ISurveyJsonService: Custom JSON serialization
    • ISurveyRepository: Custom survey storage

Roadmap

  • Enhanced drag-and-drop UI
  • Validation support
  • Markdown formatting in labels
  • Comprehensive documentation website
  • Additional question types
  • Survey analytics

Contributing

Contributions are welcome! Please open issues for feature requests or bug reports.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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
1.1.11 528 7/23/2025
1.1.10 512 7/23/2025
1.1.9 511 7/23/2025

Initial release of SurveyBuilder - enjoy!