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

  • Home
  • SEARCH
  • 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 5978587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:32:14+00:00 2026-05-22T21:32:14+00:00

I have a number of child ViewModel classes which inherit from an base ViewModel

  • 0

I have a number of child ViewModel classes which inherit from an base ViewModel class.

I pass my child ViewModel into my View, which then passes itself into a partial view.
The main view takes the child type, but the partial view takes the Parent type.

Everything displays correctly when I manually populate the properties.
However, when I Submit the form, my controller action only has properties for the Child class – none of the base class properties are completed?

e.g.

public abstract class BaseDetails
    {
        public string Name { get; set; }

        public BaseDetails()
        { }

        public BaseDetails(string name)
        {
            Name = name;
        }
    }

    public class LocalDetails:BaseDetails
    {
        public int Visits { get; set; }

        public LocalDetails()
        { }

        public LocalDetails(int visits, string name)
            :base(name)
        {
            Visits = visits;
        }
    }

With the View as simple as:

@using (Html.BeginForm())
{
    @Html.TextBoxFor(m => m.Visits)
    <br />
    @Html.Partial("Name", Model)
    <input id="Submit1" type="submit" value="submit" />
}

The partial view has a single textbox on it.

In IE: ViewSource shows the form tag is around both tetxboxes.

However, when I submit to the controller method:

[HttpPost]
public ActionResult EditLocal (LocalDetails model)

model.Visits is correctly populated, but model.Name is null?

Any ideas?
I added parameterless constructors to the classes because I got an exception upon submission if I didn’t.

  • 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-22T21:32:15+00:00Added an answer on May 22, 2026 at 9:32 pm

    Unable to reproduce. Works fine for me. Notice that I am not using any constructors with my view models because the model binder wouldn’t be able to call them and that all the properties must to have public getters and setters.

    Model:

    public abstract class BaseDetails
    {
        public string Name { get; set; }
    }
    
    public class LocalDetails : BaseDetails
    {
        public int Visits { get; set; }
    }
    

    Controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View(new LocalDetails());
        }
    
        [HttpPost]
        public ActionResult Index(LocalDetails model)
        {
            return View(model);
        }
    }
    

    View (~/Views/Home/Index.cshtml):

    @model LocalDetails
    @using (Html.BeginForm())
    {
        @Html.TextBoxFor(m => m.Visits)
        <br />
        @Html.Partial("Name", Model)
        <input type="submit" value="submit" />
    }
    

    Partial (~/Views/Home/Name.cshtml):

    @model BaseDetails
    @Html.TextBoxFor(x => x.Name)
    

    When I submit the form inside the POST Index action both model properties Name and Visits are correctly bound with values from the form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of UIViews coming into view, then going out of view
I have a service which creates a number of child processes. Using c# I
I have a Panel which hosts a number of child controls in a grid
I have a <table id=myTable> with a number of child elements: <tr><td> <span class=mySpan
We have an MDI form which contains some number of child forms which have
I have a div, which contains n number of child nodes. I have a
I have a user control which contains a number of child controls. I want
I have a number of child tables that have a foreign key to a
So I have this function that forks N number of child processes. However it
I have a collection of collections, all the child collections have the same number

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.