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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:18:46+00:00 2026-06-03T02:18:46+00:00

I am having trouble this DropDownListFor() I have test controller: model.COUNTRYNAME = Swizerland; ViewBag.Selecter

  • 0

I am having trouble this DropDownListFor()

I have test controller:

model.COUNTRYNAME = "Swizerland";
        ViewBag.Selecter = new SelectList(new[]  
        { 
            new SelectListItem { Text = "USA", Value = "USA" }, 
            new SelectListItem { Text = "Swizerland", Value = "Swizerland", Selected =true}, 
             new SelectListItem { Text = "Russia", Value = "Russia" }, 

        }, "Text", "Value", model.COUNTRYNAME);

in View

@Html.DropDownListFor(x => Model.COUNTRYNAME , (SelectList)ViewBag.Selecter)

The DropDownListFor does not have select value, it always select first value.

What is wrong?

If i use DropDownList

@Html.DropDownList("COUNTRYNAME" , (SelectList)ViewBag.Selecter)

It also don’t work.

But if I use

@Html.DropDownListFor("AAAAAAA" , (SelectList)ViewBag.Selecter)

It’s work fine and select 2nd value! What happens? I don’t understand.

Thanks

  • 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-03T02:18:47+00:00Added an answer on June 3, 2026 at 2:18 am

    Try like this:

    model.COUNTRYNAME = "Swizeland";
    ViewBag.Selecter = new[]  
    { 
        new SelectListItem { Text = "USA", Value = "USA" }, 
        new SelectListItem { Text = "Swizeland", Value = "Swizeland" },
        new SelectListItem { Text = "Russia", Value = "Russia" }, 
    };
    return View(model);
    

    and in the view:

    @Html.DropDownListFor(
        x => x.COUNTRYNAME, 
        (IEnumerable<SelectListItem>)ViewBag.Selecter
    )
    

    but a better way is to use a view model:

    model.SelectedCountry = "Swizeland";
    model.Countries = new[]  
    { 
        new SelectListItem { Text = "USA", Value = "USA" }, 
        new SelectListItem { Text = "Swizeland", Value = "Swizeland" },
        new SelectListItem { Text = "Russia", Value = "Russia" }, 
    };
    return View(model);
    

    and in the view:

    @Html.DropDownListFor(x => x.SelectedCountry, Model.Countries)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble figuring this out. If I have a checkboxlist inside a usercontrol,
Having trouble getting this to work. What's strange is that I have 10 bookmarks
Still having trouble with this language. Ok, let's say I have two objects. The
I'm having trouble solving this problem. I have to find all simple paths starting
I'm having trouble making this simple thing happen. I have this loop adding values
I have been having trouble getting this plugin to attach correctly to ajax loaded
I am having trouble with this query. I have read quite a few things
I'm having trouble on this... I have this header: #ifndef PESSOA_H #define PESSOA_H typedef
Having trouble figuring this one out.. I currently have a frmMain and a frmLoading..
I'm having trouble figuring this one out. In my view I have a dropdownlist

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.