Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asp-for taghelper not working properly in DisplayDrivers #15811

Open
Skrypt opened this issue Apr 23, 2024 · 1 comment
Open

asp-for taghelper not working properly in DisplayDrivers #15811

Skrypt opened this issue Apr 23, 2024 · 1 comment
Labels
Milestone

Comments

@Skrypt
Copy link
Contributor

Skrypt commented Apr 23, 2024

As a follow up to #15488
When a custom validation is required in the UpdateEditorAsync method of a display driver.
The asp-for taghelper doesn't display the proper mutated value.
This can be fixed by updating the updater.ModelState in that method because this is what the asp-for taghelper uses to display a value.
We may find a better fix than updating manually the updater.ModelState.

    public override async Task<IDisplayResult> UpdateAsync(
        CreateSite model,
        ProjectDetails section,
        IUpdateModel updater,
        UpdateEditorContext context
    )
    {
        var viewModel = new ProjectDetailsViewModel();

        await context.Updater.TryUpdateModelAsync(viewModel, Prefix);

        section.ProjectName = viewModel.ProjectName.ToSafeName();

        // This is the fix to get the proper value to display with the asp-for taghelper
        context.Updater.ModelState.SetModelValue(
            $"{Prefix}.{nameof(section.ProjectName)}",
            section.ProjectName,
            section.ProjectName
        );

        // After removing special chars ProjectName could become an empty string.
        if (string.IsNullOrWhiteSpace(section.ProjectName))
        {
            updater.ModelState.AddModelError(Prefix, nameof(section.ProjectName), S["Project name is required"]);
        }
    }

@sebastienros @deanmarcussen

Copy link
Contributor

We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).

This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants