views:

20

answers:

1

I have an editor template (Views/Shared/EditorTemplates/HORDER.ascx) which inherits

System.Web.Mvc.ViewUserControl<CCOK2.Models.HORDER>

My viewmodel has a one-to-many relationship which I use Html.EditorFor in order to render multiple HORDERS

<%: Html.EditorFor(model => model.PEOPLE.HORDERS, new {fred="hello"})%>

Eventually what I want to do is pass in the data for a dropdownlist, however, for the moment, I'm just trying to pass in a string "hello"

If I embed the following in HORDER.ascx

<%: ViewData.Count() %>

I get "0" output. An any attempt to get hold of the viewdata fails.

However if I use EditorFor with a single item it works as expected : I added FirstHorder to my viewmodel, set is as model.PEOPLE.HORDERS.First() then <%: Html.EditorFor(model => model.FirstOrder, new {fred="hello"})%> passes hello as expected.

Sooo.... is there any way of getting EditorFor to work with additional data when calling it with a one-to-many relationship?

EDIT: Its been suggested elsewhere that I use EditorFor in a ForEach loop against the individual HORDERS. This works (i.e. the addtional viewdata is passed correctly) but I end up with every control rendered by the EditorFor having the same id and name rather than PEOPLE.HORDERS[n].field which is not desirable.

A: 

After much messing it seems that it is not possible to do this: I consider that a bug in the framework. The workaround is to insert it into the viewdata prior to the EditorFor call.

Andiih