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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:43:28+00:00 2026-05-27T16:43:28+00:00

Its similar question that I asked yesterday here with a slight modification. Here are

  • 0

Its similar question that I asked yesterday here with a slight modification.

Here are my models

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

public class NameModel
{
    public string Title     { get; set; }
    public string FirstName { get; set; }
    public string LastName  { get; set; }
    public List<SelectListItem> Titles 
    {
        get
        {
            var list = new List<SelectListItem>();
            list.Add(new SelectListItem() { Text = "Mr.", Value = "Mr." });
            list.Add(new SelectListItem() { Text = "Mrs.", Value = "Mrs." });
            list.Add(new SelectListItem() { Text = "Ms.", Value = "Ms." });

            return list;
        }
    }

    public NameModel()
    {

    }

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

Then I have my first view ShowName.cshtml as follows

@model MyTestApp.Models.NameModel

@Html.DropDownListFor(m => m.Title, Model.Titles, Model.Titles)
<br />
@Html.LabelFor( m => m.LastName) 
@Html.TextBoxFor( m => m.LastName)       
<br />
@Html.LabelFor( m => m.FirstName) 
@Html.TextBoxFor( m => m.FirstName)       

the above view is used in ShowInfo.cshtml as below

@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" />
}

When User submit any info, follwoing controller method is called

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

The problem is that phone is fine but name is null. If I change my call of @Html.Partial("ShowName", Model.Name) to @Html.EditorFor(m => m.Name, "ShowName")
then the drop-down for Titles is displayed as an Editbox

  • 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-27T16:43:28+00:00Added an answer on May 27, 2026 at 4:43 pm

    I would recommend you using editor templates. So instead of the Html.Partial use:

    @Html.EditorFor(x => x.Name, "ShowName")
    

    and then move the partial to ~/Views/Shared/EditorTemplates/ShowName.cshtml.

    Here’s the reason why the partial doesn’t work: it generates wrong names for the input fields. So when you write:

    @Html.TextBoxFor(m => m.LastName)
    

    this generates the following markup:

    <input type="text" name="LastName" id="LastName" value="" />
    

    whereas you need:

    <input type="text" name="Name.LastName" id="Name_LastName" value="" />
    

    for the default model binder to work correctly and assign the LastName property of the Name property on your main view model.

    When you use editor templates, as shown in my example, they automatically take care of the association paths and generate proper names for the input elements.

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

Sidebar

Related Questions

I asked a similar question last week but did not get an answer that
I asked a similar question previously, but it was so vague that I couldn't
Hey a similar question has been asked before, but none that answers mine exactly.
A similar question was asked here , but the answers generally all seem to
I asked a question yesterday about a little app that I would like to
I saw that a similar question was asked before, but I don't understand another
There was a similar question asked here three years ago, but I want to
I asked a similar question over here:( Upload clocking script ), but then changed
I asked a similar question earlier here , and it got me down the
I've asked a similar question to this here: Best way to interact with EJBs

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.