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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:41:55+00:00 2026-05-28T01:41:55+00:00

I am writing MVC listing page which need to bundle with dropdownlist. As I

  • 0

I am writing MVC listing page which need to bundle with dropdownlist.
As I am very junior to ASP.net MVC, i don’t know how to make dropdownlist to run correctly and make selected dynamically.

I have two model classes

public class CycleType
{
    public int CycleTypeID { get; set; }
    public string Type { get; set; }

    public List<CycleModel> CycleModels { get; set; }
}

-----------------------------------------------------------   

public class CycleModel
{
    public int CycleModelID { get; set; }
    public int CycleTypeID { get; set; }
    public string Model { get; set; }

    public virtual CycleType CycleType { get; set; }
}

Then one Controller class,

public class CycleModelController : Controller
{
UnitOfWork<CycleModel> unitOfWork = new UnitOfWork<CycleModel>();
UnitOfWork<CycleType> unitOfWork_cycleType = new UnitOfWork<CycleType>();

...

[HttpGet]
public ActionResult Edit(int CycleModelID)
{
    CycleModel cycleModel = unitOfWork.GenericTEntityRepository.GetByID(CycleModelID);
    ViewBag.CycleType = new SelectList(unitOfWork_cycleType.GenericTEntityRepository.Get(orderBy: CycleTypes => CycleTypes.OrderBy(CycleType => CycleType.Type)));
    return View(cycleModel);
}

...
}

Then One Razor file,

<div class="editor-field">
@*Html.DropDownList("CycleType")*@
@*Html.EditorFor(model => model.CycleTypeID)*@

@Html.DropDownListFor(model => model.CycleTypeID,
                                new SelectList(ViewBag.CycleType, "Type", "CycleTypeID"))
@Html.ValidationMessageFor(model => model.CycleTypeID)
</div>

When I run my program, I get error message

DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'Type'.

1)How could I make correct this code ?
2)How could I make select item dynamically ?

Every suggestion will be really appreciated.

 

  • 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-28T01:41:56+00:00Added an answer on May 28, 2026 at 1:41 am

    The ViewBag.CycleType is already a SelectList. Hence you can use that directly.

    @Html.DropDownListFor(model => model.CycleTypeID, (SelectList)ViewBag.CycleType)
    

    You can change the controller code as follows.

    ViewBag.CycleType = new SelectList(
          unitOfWork_cycleType.GenericTEntityRepository.Get(
          orderBy: CycleTypes => CycleTypes.OrderBy(CycleType => CycleType.Type)), 
          "Type", "CycleTypeID");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing my first MVC 3 aplication (in ASP.NET) and I don't know
I am writing an ASP.Net MVC application that uses NTLM authentication, so users don't
I'm writing an small ASP.NET MVC app, which allow read and comment for a
I'm writing a MVC web app in ASP.NET MVC, which is supposed to be
I'm writing an ASP.NET MVC 3 site and I need to convert some integer
I'm writing an ASP.NET MVC 3 application with lots of classes which are not
I'm writing an app using asp.net-mvc deploying to iis6. I'm using forms authentication. Usually
I'm writing an ASP.NET MVC application and trying to use a RESX file to
I'm writing applications with ASP.NET MVC. In contrast to traditional ASP.NET you're a lot
I am developing a web application using asp.net mvc... I am listing out 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.