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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:58:18+00:00 2026-05-24T23:58:18+00:00

In my asp.net MVC 3 project I would like to create a contact that’s

  • 0

In my asp.net MVC 3 project I would like to create a contact that’s related to a company.

You can either directly create a contact OR go via the company details view and add a new contact passing the companyId to set that company already in the dropdown on the contact create form.

The problem is that I can ‘t get the passed company as default in my dropdown.

Global.asax

routes.MapRoute("contactCreate", "contact/toevoegen/{companyid}", new { action = "ContactCreate", controller = "Backend", companyid = UrlParameter.Optional });

Controller method

public ActionResult ContactCreate(int? companyid)
{
    Contact contact = new Contact();

    ViewBag.StatusList = srep.getContactStatusses();

    ViewBag.CompanyId = companyid;

    return View(contact);
}

View

@model xxx.Models.Contact

...

        <div class="editor-label">
            @Html.LabelFor(model => model.bedrijf_id)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.bedrijf_id, new SelectList(ViewBag.Bedrijven, "bedrijf_id", "bedrijf_naam",ViewBag.CompanyId), "--Kies bedrijf--")
            @ViewBag.CompanyId
            @Html.ValidationMessageFor(model => model.bedrijf_id)
        </div>
...

@ViewBag.CompanyId has a value.

Any idea why it’s not setting the selected value?

  • 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-24T23:58:18+00:00Added an answer on May 24, 2026 at 11:58 pm

    When doing a “DropDownListFor” it will try to match up the value passed in from the model for the selected value. So in your example it will use “bedrijf_id” as the selected value. It looks like you want the selected value to be from something outside of your model.

    From the comments I think what you want is just a DropDownList as follows:

    @Html.DropDownList("DropDownList", new SelectList((ViewBag.Bedrijven, "bedrijf_id", "bedrijf_naam", ViewBag.CompanyId), "--Kies bedrijf--") 
    

    Hope this helps.

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

Sidebar

Related Questions

I am embarking upon my first ASP.NET MVC project and I would like to
I am trying to start a new project (asp.net MVC) and I would like
I'm making an ASP.NET MVC project and i would like to implement business data
I'm using ELMAH to handle the exceptions in my ASP.Net MVC project. I would
If you have the following: Asp.Net MVC 2 project having object classes that define
I'm working on an editor page for a project in ASP.NET MVC. I would
As a base for discussion. Create a standard ASP.NET MVC Web project. It will
I am trying to create a user control in an ASP.NET MVC project. I
I have recently started a personal project that uses ASP.NET MVC (RC1 at the
I currently have an ASP.NET MVC 3 project, plus a class library project, that

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.