Skip to content

Razor pages - textarea asp-for binding problem #3193

Closed
@isaksky

Description

@isaksky

For razor pages, when one modifies a bound model property in an OnPost method on a page with a asp-for="MyProperty" property, the new value is shown for input controls, but not for textarea controls. For textarea, when the page is rendered, it stays the same as the AttemptedValue.

To be clear:

<input asp-for="MyProperty"> shows the new value when it is updated in OnPost, but <textarea asp-for="MyProperty"></textarea> does not.

I would expect that the behavior (whether asp-for is bidirectional) should be consistent across input types, like input, textarea, select, etc.

Workaround:

public void OnPost() {
   // MyProperty = "Something"; // Updating this way does not work for `textarea`, but does for `input`

   // But this does:
   ModelState["MyProperty"].AttemptedValue = "My new value"`
}

Same as this issue, but this is for Razor Pages:

https://github.com/aspnet/Mvc/issues/6799

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions