views:

47

answers:

1

Hi,

I have the following asp.net mvc2 template:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ncontinuity2.core.dto.TrainingLookUpContainer>" %>
<%= Html.EditorFor(x => ViewData.Model.TrainingTree, "TrainingCategory")%>

You can see that I want to bind it to a model of type TrainingLookUpContainer.

The problem is, the following mark up is being generated:

<input id="ViewData_Model_TrainingTree_TrainingCourses_0__Uid" name="ViewData.Model.TrainingTree.TrainingCourses[0].Uid" type="hidden" value="cbd43b5a-2a6a-493f-98e4-9dc9010cbaaf" />

The bit I object to is the ViewData_Model_ prefix for the id of the element and the ViewData.Model. prefix for the name attribute.

I have no idea where this prefix is coming from and it of course means that the model never gets bound when it comes to posting the form.

Is there another way, I can control the mark up that is getting generated or is this a bug in the framework. I have used EditorFor in other parts and it works fine.

Cheers

Paul

+1  A: 

change

<%= Html.EditorFor(x => ViewData.Model.TrainingTree, "TrainingCategory")%>

to

<%= Html.EditorFor(x => x.TrainingTree, "TrainingCategory")%>
Yngve B. Nilsen
Haha, bug with the framework indeed, bug with my brain.
dagda1