0

.net MVC c# application using Entity framework. I have a model (Invoices.cs) that contains property (invoice_lines) that is a collection of another model (invoiceLines.cs).

I also have an editor template in Views/Shared folder, called InvoiceLines.cshtml. the Editor template contains fields for one InvoiceLine object.

Then in the edit view, I have

@Html.EditorFor(m=>m.invoice_lines);

this is working ok, if the main model contains n invoice_lines, it repeats the editor template for each one of them. (I didnt have to include any foreach or similar anywhere, it seems mvc is smart enough to do that for me)

Now I need to create an aditional editor template for the invoice lines model, that shows only some of the fields, to be used in another view. So after reading Can I use more than one editor template for the same class in MVC3?, I have created the additional editor template in Views/Shared (basically a copy-paste of the first one, just stripped a couple field from it), called it InvoiceLineTwo.cshtml, and included it in a view for Invoice model like this

@Html.EditorFor(m=>m.invoice_lines, "InvoiceLineTwo")

but this does not work:

The model item passed into the dictionary is of type 'System.Collections.Generic.HashSet`1[MyProyect.Models.InvoiceLines]', but this dictionary requires a model item of type 'MyProyect.Models.InvoiceLines'.

searching this error, it seems it is expecting a single InvoiceLines and I am giving it a collection of them. But why with the "default" editor template this works, but not on the additional one? and how can I solve it?

patsy2k
  • 471
  • 2
  • 8
  • Need to see the headers for the two cshtml's because the model declaration is important. – AaronLS Nov 15 '17 at 14:50
  • Ops!, you are right thats exactly my case. Did not found that post before. How can i just close this question? – patsy2k Nov 15 '17 at 15:42

0 Answers0