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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:25:41+00:00 2026-06-02T20:25:41+00:00

I have the following action method in my Tournament controller: public ActionResult Edit(int id)

  • 0

I have the following action method in my Tournament controller:

    public ActionResult Edit(int id) {
        EditTournamentViewModel viewModel = new EditTournamentViewModel {
            Tournament = _tournamentService.GetTournamentByID(id),
            TournamentDivisions = _divisionService.GetTournamentDivisions(id).ToList()
        };

        ViewBag.SportID = new SelectList(_sportService.GetSports(), "SportID", "Name");
        ViewBag.CountryID = new SelectList(_countryService.GetCountries(), "CountryID", "Name");

        return View(viewModel);
    }

The two viewbag items are select lists which will be filled up. When I inspect the page with firebug the name of the SelectList for ViewBag.SportID is SportID, which is what I would expect. But I want the value that is selected there to be entered in the SportID property of the Tournament property in my viewModel. So the name should be Tournament.SportID.

I don’t understand how I can achieve this, I wasn’t able to change the SelectList’s name in Razor like this:

        <div class="editor-field"> 
            @Html.DropDownList("SportID", "Select a sport", new { name = "Tournament.SportID" } )
            @Html.ValidationMessageFor(t => t.Tournament.Sport) 
        </div>

This is the code I have in my view:

        <div class="editor-field"> 
            @Html.DropDownList("SportID", "Select a sport")
            @Html.ValidationMessageFor(t => t.Tournament.Sport) 
        </div>

A solution I could take is instead of having a Tournament property in my viewmodel, I could copy over the individual properties and then use automapper but I would like to hear if there is a fix without having to do that (unless of course what I am doing is considered very bad practice).

  • 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-02T20:25:43+00:00Added an answer on June 2, 2026 at 8:25 pm

    Did you try

    @Html.DropDownListFor(m => m.Tournament.SportID, ViewBag.SportID, "Select a sport")
    

    ?

    (if you need the acual value of Tournament.SportId, for an update, for example, you can just look at the different constructors of SelectList and change it in your “ViewBag creation”)

    CORRECTION :

    SelectList sportList = ViewBag.SportID;
    
    @Html.DropDownListFor(m => m.Tournament.SportID, sportList, "Select a sport")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following action method that calls a repository method:- public ActionResult Details(int
I have the following Action method. public ActionResult Action() { var model = new
On ASP.NET MVC 3, assume that we have following controller action: public ActionResult Index()
I have the following Action Method: [HandleFtmsError] public ActionResult PerformanceChart(ChartViewModel chart) { var x
I have the following code in my controller action method: if (User.Identity.IsAuthenticated) { //
I have the following action in my ASP.NET Web API: public IEnumerable<Car> carssOfUser(int id,
I have the following controller action and test. I'm new to testing with Shoulda
I have a controller with the following action code: public JsonResult CheckPasswordStrength(string password, string
I have the following route defined routes.MapRoute( ItemName, {controller}/{action}/{projectName}/{name}, new { controller = Home,
I have the following code in my post action method for Edit. JobCardService.Update(viewData.JobCard); var

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.