.Net MVC UserControl - RenderPartial or EditorFor

I have a view containing usercontrol. User control is displayed using:

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

My problem is that usercontrol displays the values ​​from the model perfectly, but when I publish the values edited in usercontrol, they do not map to the model. General . I know that I can find the values ​​in Request.Form, but I really thought that MVC would be able to match these values ​​with the model.

My user control:

 <%@ 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 am using .Net MVC 2

Thanks for any help!

+3
source share
1 answer

The problem is solved!

:

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

:

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

usercontrol Views- > Shared- > EditorTemplates "GeneralViewModel.ascx"

+2

Source: https://habr.com/ru/post/1743971/


All Articles