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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:28:06+00:00 2026-06-08T15:28:06+00:00

I added a dynamically added object like: @Html.EditorFor(model => model.Province) My model contains the

  • 0

I added a dynamically added object like:

@Html.EditorFor(model => model.Province)

My model contains the Province properties but the view didn’t show the object at the begining. I made it visible by .show() method.

However, in the controller, I found always the value for Province is null. How to make it accessible from dynamically added object like this?

Added:
my model looks like this:

public class Location
{
    [Required]
    public int ID { get; set; }
    [Required]
    public string Name { get; set; }
    public string Description { get; set; }
    public string Street { get; set; }
    public string City { get; set; }
    [Display(Name = "State/Province")]
    public string Province { get; set; }
}

controller:

    [HttpPost]
    public ActionResult Create(Location location)
    {
        if (ModelState.IsValid)
        {
            db.Location.Add(location);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
    }

view:

    <div class="editor-label">
        @Html.LabelFor(model => model.Province)
    </div>
    <div class="editor-field">
    <div id="province_ddl">
        @Html.DropDownListFor(
            x => x.Province,
            Enumerable.Empty<SelectListItem>(),
            "-- Select State/Province --"
            )
    </div>
    <div id="province_tb" style="display: none">
        @Html.EditorFor(model => model.Province)
    </div>
        @Html.ValidationMessageFor(model => model.Province)
    </div>

When I use dropdownlist, it will have right value for Province property. However, if I made textbox control visible, it won’t have value i.e., got null value in the controller.

  • 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-06-08T15:28:08+00:00Added an answer on June 8, 2026 at 3:28 pm

    You cannot have 2 input fields in the same form with the same name (Province in your case). Well, actually you can but only the value of the first will be sent to the controller. So if you keep the dropdown it will be the selected value of the dropdown that will always be sent to the controller. So basically you have to decide. You might disable one of the fields (by adding the disabled="disabled" attribute to it, could be done dynamically) to force only the value of the other to be sent.

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

Sidebar

Related Questions

I dynamically added rows to a table but it doesn't seem to take hover
I added onkeyup javascript for a dynamically added textbox in javascript... But it doesnt
I'd like to load dynamically a Class object defined by the Guava library from
I would like to be able to choose which properties is added to my
This is an unusual question, but I'd like to dynamically generate the __slots__ attribute
I have created jframe in which jpanels are added dynamically what i can't do
I've been having problems getting jqmodal modal dialogs to display on links added dynamically
I am trying to see how to find a tag that was added dynamically
i added checkboxes dynamically to panel. for (int intControlIndex = 0; intControlIndex < dsTagsList.Tables[0].Rows.Count;
If buttons are dynamically added in wpf from code behind how can you add

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.