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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:22:05+00:00 2026-06-18T02:22:05+00:00

I am using asp.net mvc 4 web app c#. I have the following model:

  • 0

I am using asp.net mvc 4 web app c#. I have the following model:

 public class Job
{
    public int id { get; set; }
    public string description { get; set; }
    public string company { get; set; }
    public JobType jobType { get; set; }


    //public int JobTypeId { get { return this.jobType.id; } }
}

Now I want to write a create action where the jobType attribute is set through a DropDownList. The create action:

//
    // GET: /Job/Create

    public ActionResult Create()
    {
        IEnumerable<JobType> jobtypes = db.JobTypes.ToList();
        ViewData.Add("jobTypeList", new SelectList(jobtypes , "id", "name"));
        return View();
    }

    //
    // POST: /Job/Create

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

        return View(job);
    }

View:

<div class="editor-label">
        @Html.LabelFor(model => model.jobType)
    </div>
    <div class="editor-field">
        @Html.DropDownList("jobTypeList")
        @Html.ValidationMessageFor(model => model.jobType)
    </div>

The DropDownList is working fine listing existing jobtypes. However, when a job is created the jobetype of the job is not set (the jobtype id is not set in the job row of the created job). As I am new to asp.net mvc, I am not sure what the form passes to the post create action: Does it pass the jobtype object or the jobtype id? Why does it not set the jobtype id for the created job? Do I have to set the jobtype id my self in post create action? If so how do I get the selected value of the DropDownList?

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

    EDIT:

    So to get the id of the selected value in the drop-down list, I just have a line like this:

    int contentId= APIFactory.getContentAPI().getID(department.SelectedValue);
    

    where the function getId() takes a name (the value in the drop-down) and then does a database query for the id of the department selected. Here is my getID() function

    public int getID(String deptName)
    {
        Dictionary<string, object> where = new Dictionary<string, object>();
        where.Add(DEPTNAME, deptName);
        DataTable dt = db.Query(ID, TABLE, where);
        return (int)dt.Rows[0][ID];
    }
    

    Note: You don’t need the whole APIFactory thing for this, you could just throw the query in instead of the line I have, and it would work just as well. However, if you are using the same queries a lot, I would recommend it.

    EDIT:
    Since you are using a cshtml page and not a aspx page, use the method described here to get the value, and then my method to get the id:
    How to get Dropdownlist selected value

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

Sidebar

Related Questions

In my web app (ASP.NET MVC), I send an email using the following: MailMessage
I have an asp.net MVC web app using Kendo UI Grids with client templates.
I'm developing an web app using asp.net mvc. I have a List in Cache
I'm building a web app using EF Code First and ASP.NET MVC. I have
I have an ASP.NET MVC 4 Web API app using EntityFramework for ORM. In
I'm using ASP.net MVC C# in Visual Studio Web Dev. I have a couple
I'm using a ExtJS DateField control in an ASP.NET MVC web application. I've set
I've got a ASP.NET MVC web app which uses forms authentication. I'm using ActiveDirectoryMembershipProvider
I have an ASP.NET MVC web app and in one of the controller actions
I am using ASP.NET MVC along with JQueryMobile in a web app. I want

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.