3

I have a View that contains a usercontrol. The usercontrol is rendered using:

<% Html.RenderPartial("GeneralStuff", Model.General, ViewData); %>

My problem is that the usercontrol renders nicely with values from the model but when I post values edited in the usercontrol they are not mapped back to Model.General. I know I can find the values in Request.Form but I really thought that MVC would manage to map these values back to the model.

My usercontrol:

 <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<namespace.Models.GeneralViewModel>" %>

<fieldset>        
    <div>
        <%= Html.LabelFor(model => model.Value)%>
        <%= Html.TextBoxFor(model => model.Value)%>            
    </div>
</fieldset>

I'm using .Net MVC 2

Thanks for any help!

tereško
  • 58,060
  • 25
  • 98
  • 150
Andreas
  • 659
  • 6
  • 17
  • how are you trying to send the value back to the model? through an input? – Ayo May 04 '10 at 13:20
  • Yes, in an input text element. See my code snippet above (<%= Html.TextBoxFor(model => model.Value)%>) – Andreas May 04 '10 at 17:09

1 Answers1

2

Problem solved!

My usercontrol is rendered with:

<%= Html.EditorFor(model => model.General); %>

My model looks like this:

public class TestEditViewModel
{
    [UIHint("GeneralViewModel")]
    public GeneralViewModel General { get; set; }
}

And my usercontrol is placed under Views->Shared->EditorTemplates and named "GeneralViewModel.ascx"

Andreas
  • 659
  • 6
  • 17