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 6980891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:05:07+00:00 2026-05-27T18:05:07+00:00

Here are my model. public class InfoModel { public NameModel Name { get; set;

  • 0

Here are my model.

public class InfoModel
    {
        public NameModel Name { get; set; }
        public string Phone { get; set; }
    }

public class NameModel
    {
        public string FirstName { get; set; }
        public string LastName  { get; set; }

        public NameModel(string first, string last)
        {
            this.FirstName = first;
            this.LastName = last;
        }
    }

Then I have a partial View just for displaying names as follows

@model MyTestApp.Models.NameModel

@Html.LabelFor( m => m.LastName) 
@Html.TextBoxFor( m => m.LastName)       
<br />
@Html.LabelFor( m => m.FirstName) 
@Html.TextBoxFor( m => m.FirstName)       

Then there is a view for ShowInfo

@model MyTestApp.Models.InfoModel

@using (@Html.BeginForm())
{
    @Html.Partial("ShowName", Model.Name)
    <br />
    @Html.LabelFor( m => m.Phone) 
    @Html.TextBoxFor(m => m.Phone)
    <br />
   <input type="submit" value="Submit Info" />
}

Now user submit any info, following controller method is called

 [HttpPost]
 public ActionResult ShowInfo(InfoModel model)
 {
    ...
 }

Problem is when i inspect the value of model, phone is fine but name is null. Any ideas how to make it work?

  • 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-27T18:05:08+00:00Added an answer on May 27, 2026 at 6:05 pm

    The DefaultModelBinder class uses Activator.CreateInstance(typeToCreate) internally to create the model classes. Your NameModel class dosn’t have a default constructor so the DefaultModelBinder can’t instantiate it. So if you add the default constructor it should work.

    EDIT
    It won’t work Partial view you need to use an EditorTemplate instead:
    Create a folder under your view folder with the name EditorTemplates and put your ShowName.cshtml there add in your main view use:

    @using(Html.BeginForm())
    {
        @Html.EditorFor(m => m.Name, "ShowName")
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model public class Foo{ public int Id{get;set;} public string Name {get;
Here's my model public class Movie { public int MovieID { get; set; }
I have this model: public class Package { public string CustomerName { get; set;
Here is my model: public class NewsCategoriesModel { public int NewsCategoriesID { get; set;
Here is my model public class Horse { public int HorseId { get; set;
I have following model: public class FormularModel { [Required] public string Position { get;
Model: public class Model { public ItemType Type { get; set; } public int
Consider the following model: public class BandProfileModel { public BandModel Band { get; set;
ok say i have the following model: public class bar{ public string bar {get;
Here are the domain model classes: public abstract class BaseClass { ... } public

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.