0

I created EditorTemplate:

enter image description here

With code:

@model RentSite.Web.UI.Models.PhonesViewModel

<div>
@Html.TextBoxFor(m=>Model.Number)  @Html.TextBoxFor(m => Model.From)  @Html.TextBoxFor(m => Model.To)
</div>

And i try to use it like this:

@model RentSite.Web.UI.Models.ContactsViewModel

@{
    ViewBag.Title = "AddContact";
}

<h2>AddContact</h2>
@using (Html.BeginForm("AddContact","Contact",FormMethod.Post, new {enctype = "multipart/form-data"}))
{    
    <input type="file" name="Image"/>
    @Html.EditorFor(model=>model.Phoness )
    <input type="submit" value="Add"/>
}

ContactsViewModel looks like this:

namespace RentSite.Web.UI.Models
{
    public class ContactsViewModel
    {
        public string Name { get; set; }
        public IEnumerable<PhonesViewModel> Phoness { get; set; }
    }
}

But i can't see any Editor at the page... Why??

korovaisdead
  • 6,271
  • 4
  • 26
  • 33

1 Answers1

2

Your editor template model says its of type PhonesViewModel but you are calling it with model.Phoness which is IEnumerable of PhoneViewModel.

In your Editor template file, Change @model RentSite.Web.UI.Models.PhonesViewModel

to

@model IEnumerable<RentSite.Web.UI.Models.PhonesViewModel>
Shyju
  • 214,206
  • 104
  • 411
  • 497
  • It doesn't exactly what I need. And, finally, it doesn't work. – korovaisdead Jan 07 '12 at 14:16
  • what is your expected result ? – Shyju Jan 07 '12 at 14:17
  • I want to be able to add one-or-more phones through this ContactsViewModel. – korovaisdead Jan 07 '12 at 14:45
  • As per your code, this editor template will display 3 textboxes (number,from and to) to each entry in your IEnumerbale.Your question was about the content is not displaying. Are you sure you have items in the model.Phoness ? Put breakpoint in your controller action and see it before passing it to the view. – Shyju Jan 07 '12 at 15:20
  • I had already understand my mistake. I'm trying to add new phone, but not to display. Can you give me any advice, how can I organize this? How can i add one-or-more phones? – korovaisdead Jan 07 '12 at 15:27
  • take a look at this http://stackoverflow.com/questions/5763634/asp-net-mvc-3-dynamic-controls – Shyju Jan 07 '12 at 15:42