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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:45:50+00:00 2026-06-02T02:45:50+00:00

Hi I am working in a MVC 3 application. I have a Create Form

  • 0

Hi I am working in a MVC 3 application. I have a Create Form with following code.

@model Xrm.Student
@{
ViewBag.Title = "Create Student Record";
 }
@using (Html.BeginForm("Create", "Student", FormMethod.Post))
{
    <div class="editor-label">
         @Html.LabelFor(model => @Model.FirstName)
    </div>
    <div class="editor-field">                                      
         @Html.EditorFor(model => @Model.FirstName)
         @Html.ValidationMessageFor(model => @Model.FirstName)
    </div>
<div>
    <input id="Submit1" type="submit" value="Submit" />
</div>
}

I want to add a new drop down under Firsname field which should be populated with pubjects. Subject is different Entity. I could be very easy, but I am newbie with MVC so I just stuck here. Can anyone please suggest me the way to achieve it.

Thanks and Regards

  • 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-02T02:45:52+00:00Added an answer on June 2, 2026 at 2:45 am

    I would define a view model:

    public class MyViewModel
    {
        public Student Student { get; set; }
    
        [DisplayName("Subject")]
        [Required]
        public string SubjectId { get; set; }
    
        public IEnumerable<Subject> Subjects { get; set; }
    }
    

    and then have your controller populate and pass this view model to the view:

    public ActionResult Create()
    {
        var model = new MyViewModel();
        model.Student = new Student();
        model.Subjects = db.Subjects;
        return View(model);
    }
    

    and finally have your view strongly typed to the view model:

    @model MyViewModel
    @{
        ViewBag.Title = "Create Student Record";
    }
    @using (Html.BeginForm())
    {
        <div class="editor-label">
             @Html.LabelFor(x => x.Student.FirstName)
        </div>
        <div class="editor-field">                                      
             @Html.EditorFor(x => x.Student.FirstName)
             @Html.ValidationMessageFor(x => x.Student.FirstName)
        </div>
    
        <div class="editor-label">
             @Html.LabelFor(x => x.SubjectId)
        </div>
        <div class="editor-field">                                      
             @Html.DropDownListFor(
                 x => x.SubjectId, 
                 new SelectList(Model.Subjects, "Id", "Name"),
                 "-- Subject --"
             )
             @Html.ValidationMessageFor(x => x.SubjectId)
        </div>
    
        <div>
            <input type="submit" value="Submit" />
        </div>
    }
    

    The "Id" and "Name" values I used for the SelectList must obviously be existing properties on your Subject class that you want to be used as respectively binding the id and the text of each option of the dropdown.

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

Sidebar

Related Questions

I'm working on a MVC application in which the Model is implemented using an
I am working with an ASP.NET MVC application. I have one master page having
I am working on an asp.net MVC 3 application. I have a C# function
I'm working through a previous webforms application to convert it to MVC and have
Im working on a MVC application, and was just wondering.. Should I be using
I am trying to create an ASP.NET MVC application, using Spring.NET to inject dependencies.
FYI, I'm working on my first MVC web application using MVC 3 and Razor
I am busy working with an ASP.NET MVC 3 application and using Windows 7.
I am working on a mvc3.0 app using EF code first and mvc scaffolding.
Currently working on an ASP.NET MVC 3.0 application and using FormsAuthentication . When the

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.