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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:48:39+00:00 2026-05-30T18:48:39+00:00

I have a teacher rating system. When I got to create a new comment

  • 0

I have a teacher rating system. When I got to create a new comment about a teacher, I have a dropdownlistfor() list of classes that are available to the student can choose from. I want that dropdownlist to pass a Course Object in upon submitting but instead it’s just passing in null and giving me an error. I’m using a viewbag to display all the available courses.

Model:

    public class TeachersRatingsWall
{

    public int ID { get; set; }



    [Range(1, 5, ErrorMessage = "Invalid rating")]
    public Int32 StarRating { get; set; }

    [Required]
    public string PostComment { get; set; }

    public DateTime PostDate { get; set; }

    [Required]
    public string Teacher { get; set; } //?   or public Teacher Teacher { get; set; }

    public Guid PosterID { get; set; }

    public string PosterUserName { get; set; }

    //[Required] 
    public Course Course { get; set; }

    public Guid CourseID { get; set; }




    }
 }

Ropository:

     public IQueryable<TeachersRatingsWall> Select()
    {
        return table.Select(x => new TeachersRatingsWall
                                {
                                  ID = x.ID,
                                  StarRating = x.StarRating,
                                  PostComment = x.PostComment,
                                  PostDate = x.PostDate,
                                  Teacher = x.Teacher,
                                  PosterID = x.PosterID,
                                  CourseID = x.CourseID,
                                  Course = new Course {
                                      ID = x.CourseID,
                                      CourseNumber = x.CourseEntity.CourseNumber,
                                      Department = x.CourseEntity.Department,
                                      Description = x.CourseEntity.Description,
                                      Name = x.CourseEntity.Name

                                                        }

                                });

    }

Controller:

public ActionResult Create()

{

     ViewBag.allcourses = coursesservice.GetAllCoursesNamesAndNumbers().Select(x => x.Department + " " + x.CourseNumber);

        //-----------------------------------------------------------------------------------------------------------
        return View();
    } 


   [HttpPost]
    public ActionResult Create(TeachersRatingsWall collection)
    {           
        try
        {
            // TODO: Add insert logic here
            collection.PosterID = ((Guid)Membership.GetUser().ProviderUserKey);
            collection.PostDate = System.DateTime.Now;

            teacherratingservice.CreateComment(collection);
            return RedirectToAction("Index");
        }
        catch
        {
            return View();
        }
    }

View – Create.cshtml

        <div class="editor-label">
        @Html.Label("Course:")
    </div>
    <div class="editor-field">
        @Html.DropDownListFor(model => model.Course, new SelectList(ViewBag.allcourses))

    </div>
  • 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-30T18:48:41+00:00Added an answer on May 30, 2026 at 6:48 pm

    On your model you need the following

    public int CourseId { get; set; }
    

    and

    public IList<SelectListItem> Courses { get; set; }  
    

    On your Controller you have to populate these two model items together then in your view it should be something like this

    @Html.DropDownListFor(model => model.CourseId, Model.Courses, "")
    

    MVC will auto map that for you and select the necessary items for GET and POST

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

Sidebar

Related Questions

I have a list of tables i.e. student, teacher, staff, dept. and so on
I have two classes Teacher and Student . I am trying to get teacher
I have two classes, a Teacher class and a Student class. In my program
I have two classes, Student and Teacher, Student has one concrete method: takeCourse; Teacher
I have Teacher, Student, and Parent models that all belong to User. This is
I have a Relationship table that links teachers to students Teacher Student 1 1
Suppose that we have this class: public enum KindOfPerson { Student, Teacher, ... }
We have studied the Variable Elimination recently and the teacher emphasizes that it is
I have a teacher model which has_many students. When I render a student (as
I have a table Teacher that contains a TeacherPIN as well as a table

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.