Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

textarea with asp-for not filled #3964

Closed
markusvt opened this issue Jan 21, 2016 · 13 comments
Closed

textarea with asp-for not filled #3964

markusvt opened this issue Jan 21, 2016 · 13 comments
Assignees

Comments

@markusvt
Copy link

I inserted a Textarea and bound it to my model like this:
<textarea rows="3" class="form-control" asp-for="@Model.Description"></textarea>

When I fill the Textarea and save it, the entered data is correctly saved in my Database. But if I open the Form afterwards, the textarea is not filled at all (all other input elements have the correct values)

I played around a bit and found out that
<textarea rows="3" class="form-control" asp-for="@Model.Description">@Model.Description</textarea>
fills it correctly. Maybe there is a bug in the textarea TagHelper?

@dougbu
Copy link
Contributor

dougbu commented Jan 21, 2016

Your workaround definitely should not be required. What is the type of Model.Description? Is the element's content correctly populated if you switch to

<textarea rows="3" class="form-control" asp-for="Description"></textarea>

Since we haven't seen this, I'd appreciate a chance to look at your repro project. Could you upload something to a GitHub repo?

@markusvt
Copy link
Author

The following is a part of my Model:

public class Basicpart_Value : IEntity
{
        public long Id { get; set; }

        [Required]
        public string Name { get; set; }
        public string Description { get; set; } = "";
     ...
}

I know there is an empty initial value for the Description, but the model was correctly loaded from the database.

Edit: I just did some more research and decorated the Description with
[DataType(DataType.MultilineText)]
Now the textarea is correctly filled.

@dougbu
Copy link
Contributor

dougbu commented Jan 22, 2016

@markusvt what you're describing is quite odd because [DataType(DataType.MultilineText)] should only impact the @Html.Editor[For[Model]](...) HTML helpers. Further, only the @Html.Display[For[Model]](...) and @Html.Editor[For[Model]](...) HTML helpers and the <input> tag helper do anything related to DataTypeAttribute.

Could you please post your .cshtml file (the portion that deals with the Description property) and any generated HTML for that property?

@Eilon
Copy link
Contributor

Eilon commented Jan 25, 2016

@dougbu can you try to repro this with various scenarios?

@dougbu
Copy link
Contributor

dougbu commented Jan 25, 2016

@dougbu can you try to repro this with various scenarios?

Sure though I'd definitely appreciate @markusvt's specific repro.

@markusvt
Copy link
Author

hey, unfortunately i cannot upload the whole repository, but maybe I can describe it..

  1. there are 2 projects in my solution: "Database" and "Intranet"
  2. in the "Database" project are the models. In this specific case, there is a model class called "Basicpart_Value" that looks like that:
[Table("Caravan_Basicpart_Value")]
public class Basicpart_Value : IEntity
    {
        public long Id { get; set; }

        [DataType(DataType.MultilineText)]
        public string Description { get; set; } = "";
   }

3: in the "Intranet" project, there are some Areas, espacially the "Caravan" Area with a View "ValueForm"
that Form looks in general like that:

<div id="@ViewBag.guid" class="UserForm">
    <form asp-route-id="@Model.Id" asp-route-area="Caravan" asp-controller="Basicpart" asp-action="SaveValue" method="post" class="form-horizontal" role="form">
        <div asp-validation-summary="ValidationSummary.All" class="failureNotification alert alert-danger"></div>

        <input type="hidden" asp-for="@Model.Basicpart_TypeId" />

        <Tabs>
            <Tab title="Allgemein">
                <div class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label" asp-for="@Model.Name"></label>
                        <div class="col-sm-10">
                            <input autofocus class="form-control" asp-for="@Model.Name" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" asp-for="@Model.Price"></label>
                        <div class="col-sm-10">
                            <input class="form-control" asp-for="@Model.Price" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" asp-for="@Model.Description"></label>
                        <div class="col-sm-10">
                            <textarea rows="3" class="form-control" asp-for="@Model.Description"></textarea>
                       </div>
                  </div>
                </div>
            </Tab>
        </Tabs>

        <button type="button" class="btn btn-default" onclick="closeSite()">Close</button>
        <button type="submit" class="btn btn-primary">Save</button>
    </form>
</div>

Maybe I should mention: the 'Tab' and 'Tabs' Tags are TagHelper that generate some HTML for bootstrap Tabs. Maybe there is a Problem with that nesting?

@dougbu
Copy link
Contributor

dougbu commented Jan 29, 2016

@markusvt what is the @model directive in your view? It can't be @model Basicpart_Value because that type doesn't contain Name or Price properties, at least that you've shown. If not Basicpart_Value, please provide the exact definition of the Description property in the actual model type.

@dougbu
Copy link
Contributor

dougbu commented Feb 3, 2016

@markusvt I remain unable to reproduce this issue with the information provided so far. Any other or corrected information you can provide? Or any smaller project where you've seen this issue?

@markusvt
Copy link
Author

markusvt commented Feb 3, 2016

I did post just a fraction of the Basicpart_Value class. If it is possible i can put the whole project in a ZIP file and send it to you?

@dougbu
Copy link
Contributor

dougbu commented Feb 3, 2016

@markusvt that's fine. Please send to dougbu at microsoft dot com.

@dougbu
Copy link
Contributor

dougbu commented Feb 8, 2016

Had a good exchange w/ @markusvt. We eventually determined the <textarea rows="3" class="form-control" asp-for="@Model.Description"></textarea> in the first comment was actually <textarea rows="3" class="form-control" asp-for="@Model.Description"/>. So the <textarea> tag helper is acting as designed and this issue is very similar to #4058.

/cc @DamianEdwards and @barrytang, we have had a few issues filed around self-closed but non-empty HTML elements. Anything we can do better to show .cshtml authors what they're writing is invalid?

@barrytang
Copy link

@dougbu, I believe you have a tooling issue opened for @ToddGrun already. If not, can you open one? Thanks!

@dougbu
Copy link
Contributor

dougbu commented Feb 9, 2016

Couldn't find an existing Tooling issue; filed aspnet/Tooling#398.

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

No branches or pull requests

4 participants