Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 682685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:37:26+00:00 2026-05-14T01:37:26+00:00

I have the following types and classes: namespace MVC.Models public class Page { public

  • 0

I have the following types and classes:

namespace MVC.Models

public class Page 
{
   public EditableContent Content {get; set; }
}

public class EditableContent
{
    public TemplateSection SidebarLeft {get; set; }
    public TemplateSection SidebarRight {get; set; }
}

I want to edit the Page instance in my Edit.aspx View. Because EditableContent is also attached to other models, I have a PartialView called ContentEditor.ascx that is strongly typed and takes an instance of EditableContent and renders it.

The rendering part all works fine, but when I post – everything inside my ContentEditor is not binded – which means that Page.Content is null.

On the PartialView, I use strongly typed Html Helpers to do this:

<%= Html.HiddenFor(m => m.TemplateId) %>

But because the input elements on the form that are rendered by ContentEditor.ascx does not get the Content prefix to its id attribute – the values are not binded to Page.

I tried using loosely typed helpers to overcome this:

<%= Html.Hidden("Content.TemplateId", Model.TemplateId) %>

And when I’m dealing with a property that is a List<T> of something it gets very ugly. I then have to render collection indexes manually.

Should I put both Page and EditableContent as parameters to the controller action?:

public ActionResult Edit(Page page, EditableContent content) { ... }

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:37:26+00:00Added an answer on May 14, 2026 at 1:37 am

    I would suggest you to use the EditorFor helper

    Model:

    public class EditableContent
    {
        public string SidebarLeft { get; set; }
        public string SidebarRight { get; set; }
    }
    
    public class Page
    {
        public EditableContent Content { get; set; }
    }
    

    Views/Home/Index.aspx:

    <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ToDD.Models.Page>" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
        Home Page
    </asp:Content>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <% using (Html.BeginForm()) { %>
        <%-- 
        This is the important part: It will look for 
        Views/Shared/EditorTemplates/EditableContent.ascx
        and render it. You could also specify a prefix
        --%>
        <%= Html.EditorFor(page => page.Content, "Content") %>
        <input type="submit" value="create" />
    <% } %>
    </asp:Content>
    

    Views/Shared/EditorTemplates/EditableContent.ascx:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ToDD.Models.EditableContent>" %>
    
    <%= Html.TextBoxFor(m => m.SidebarLeft) %>
    <br/>
    <%= Html.TextBoxFor(m => m.SidebarRight) %>
    

    And finally Controller/HomeController:

    public class HomeController : Controller
    {
        public ActionResult Edit()
        {
            var page = new Page
            {
                Content = new EditableContent
                {
                    SidebarLeft = "left",
                    SidebarRight = "right"
                }
            };
            return View(page);
        }
    
        [HttpPost]
        public ActionResult Edit(Page page)
        {
            return View(page);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following types [Serializable, XmlType(Namespace=http://mycompany/foo] public sealed class Limit { [XmlElement(ElementName=Value1)] public
I have the following classes: public class Person { public String FirstName { set;
I have the following code: Imports MySql.Data.MySqlClient Imports MySql.Data.Types Public Class FormMain Private Sub
Here is my problem in C# : I have the following classes: public class
Assuming I have the following classes in an application: A base class: public abstract
Suppose I have the following types of data: class Customer { String id; //
Please consider the following three .NET types: I have an interface, an abstract class,
I have three classes in my C# program. Get the following error: Cannot implicitly
I have the following situation (simplified): a.h: #include <boost/serialisation/serialisation.hpp> class B; using namespace std;
Let's say I have the following classes and interfaces in my MVC 2 project:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.