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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:53:58+00:00 2026-06-11T01:53:58+00:00

How exactly should a select tag be mapped to an MVC Model variable, I’ve

  • 0

How exactly should a select tag be mapped to an MVC Model variable, I’ve tried everything that I can possibly think of, but every time I check the post method on the controller, the variable that is supposedly binded to the dropdown returns null.

View:

<script type="text/javascript">
var counter = 1;
$('#btnAddLocation').click(function (e) {
    e.preventDefault();
    $("#tblAddLocation").find('tbody')
            .append($('<tr>')
                .append($('<td>')
                    .append($('@Html.LabelFor(m => m.Location)')
                    )
                )
                .append($('<td>')
                    .append($('<select name=Location id=Location' + counter++ + ' class=gradientTextbox>')
                    )
                )
                .append($('<td>')
                    .append($('@Html.LabelFor(m => m.Description)')
                    )
                )
                .append($('<td>')
                    .append($('@Html.EditorFor(m => m.Description)')
                    )
                )
            );

    $.getJSON("/Locations/GetAllLocations", function (data) {
        var items = "<option selected></option>";
        $.each(data, function (i, item) {
            items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
        });

        $("#Location" + (counter - 1)).html(items);
    });
});
</script>

Controller:

[HttpPost]
    public ActionResult ActionName(MyModel model, List<string> Location, List<string> Description) {
        return Json(new { success = true });
    }

The Description variable in the controller code works fine, but the list for Location returns the right count, but all the items are null.

Any suggestions on how to handle this issue?

  • 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-11T01:53:59+00:00Added an answer on June 11, 2026 at 1:53 am

    Well i figured out the solution.

    Html.DropDownListFor version

    <select id="Location" name="Location" class="gradientTextbox">
        <option>option 1</option>
        <option>option 2</option>
        <option>option 3</option>
    

    My version

    <select id="Location1" class="gradientTextbox" name="Location">
        <option selected=""></option>
        <option value="null">option 1</option>
        <option value="null">option 2</option>
        <option value="null">option 3</option>
    

    Noticing the subtle difference, the real issue of the problem lies in this line of the code:

    items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
    

    In order to fix my code, the aforementioned line should be replaced with:

    items += "<option>" + item.Text + "</option>";
    

    Problem fixed. Thanks for the help @Gabe

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

Sidebar

Related Questions

I have an inputfield that should exactly look like the normal body-text. It does
I accidentally deleted my previous post. Could I know exactly why I should compile
i know it should be context. what exactly is a context though. usually when
I'm still not getting exactly how a custom CursorAdapter should work, so after hard
Exactly when are an Activity 's fields that are annotated with @InjectView or @InjectResource
Questions exactly like this have been asked before, i've read them all and tried
This should be something encountered by programmers often, but I never tried to get
Not exactly an error, but I think I am missing something important here.. class
Microsoft is pretty clear that .NET identifiers or parameters should not contain abbreviations. Straight
I have a TStringGrid where the selected row (max 1, no multi-select) should always

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.