PostureOfLearning
PostureOfLearning

Reputation: 3541

Html.TextBoxFor() does not generate any html markup

I've got 4 shared EditorTemplates: Tab, Group, Line & Item.

Tab.cshtml:

@model AWMCCRM.Web.ViewModels.Tab
@Html.HiddenFor(vm => vm.Name)
<div id="[email protected](" ", string.Empty)" class="tab-content">
     @Html.EditorFor(vm => vm.Groups)
</div>

Group.cshtml:

@model AWMCCRM.Web.ViewModels.Group
@Html.HiddenFor(vm => vm.Name)
<fieldset>
    <legend>@Model.Name</legend>
    @Html.EditorFor(vm => vm.Lines)
</fieldset>

Line.cshtml:

@model AWMCCRM.Web.ViewModels.Line
@Html.HiddenFor(vm => vm.Name)
@Html.EditorFor(vm => vm.Items)

Item.cshtml:

@model AWMCCRM.Web.ViewModels.Item

<div class="@Model.DivClass">
    <p class="@Model.PClass">
        Html.LabelFor(vm => vm.ValueString, Model.Name);
        Html.TextBoxFor(vm => vm.ValueString);
    </p>
</div>

Corresponding ViewModels:

public class Tab
{
    public string Name { get; set; }
    public List<Group> Groups { get; set; }
}
public class Group
{
    public string Name { get; set; }
    public List<Line> Lines { get; set; }
}
public class Line
{
    public string Name { get; set; }
    public List<Item> Items { get; set; }
}
public class Item
{
    public string Name { get; set; }
    public string Description { get; set; }
    public string ValueString { get; set; }
    public string DivClass { get; set; }
    public string PClass { get; set; }
}

In my main View I have this:

  @Html.EditorFor(vm => vm.Tabs)

The code that gets generated looks like this:

<div id="tab-Tab-1" class="tab-content">
<input id="Tabs_0__group_Name" name="Tabs[0].group.Name" type="hidden" value="Group0" />
<fieldset>
    <legend>Group0</legend>
<input id="Tabs_0__group_line_Name" name="Tabs[0].group.line.Name" type="hidden" value="Line0" />
<div class="_20">
    <p class="">
    </p>
</div>
</fieldset>
</div>

As you can see, the div and the p gets generated, but there is no textbox or label.

I have also tried this in the item template instead, but it didn't work either:

Html.TextBoxFor(vm => Model.ValueString);

Any ideas why or what I need to do?

Thanks

Upvotes: 3

Views: 1676

Answers (1)

PostureOfLearning
PostureOfLearning

Reputation: 3541

Ok, I'm almost too embarrassed to post the solution but here it is...

I was missing the '@' in the beginning of the lines;

in my item.cshtml

    Html.LabelFor(vm => vm.ValueString, Model.Name);
    Html.TextBoxFor(vm => vm.ValueString);

should be

    @Html.LabelFor(vm => vm.ValueString, Model.Name);
    @Html.TextBoxFor(vm => vm.ValueString);

Upvotes: 8

Related Questions