3

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

2
  • Please make sure that the Model is not null. Commented Jul 23, 2013 at 7:34
  • @UmairP, I've just double checked and the Model is not null. It has a value and so does Model.ValueString. Any other thoughts? Commented Jul 23, 2013 at 11:07

1 Answer 1

8

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.