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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:10:05+00:00 2026-05-23T07:10:05+00:00

I have been wrestling with what should be a very simple thing for weeks

  • 0

I have been wrestling with what should be a very simple thing for weeks now. I simply want to create a dropdownlist in asp.net mvc 3 razor html page and I want the data for the dropdownlist to come from a model.

My Model is as follows which is in the Models.Project namespace.

public class Project
{
    public Project()
    {
        CategoryId = 0;
        Name = "";
        Description = "";
        //Categories = new Dictionary<int, string>();

        Entities _db = new Entities(); //ef4
        CateogoriesList = from c in _db.Categories 
                        orderby c.Name
                        select c.Name;
    }

    public int CategoryId { get; set; }

    [Required]
    [DataType(DataType.Text)]
    [Display(Name = "Project Name")]
    public string Name { get; set; }

    [Required]
    [DataType(DataType.MultilineText)]
    [Display(Name = "Project Description")]
    public string Description { get; set; }

    public IQueryable<string> CateogoriesList;

}

My Controller action is as follows

public ActionResult Create()
{
    Models.Project.Project proj = new Models.Project.Project();
    return View(proj);
}

My Razor view has the following relevant code …

@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@model Models.Project.Project


@using (Html.BeginForm())
{
    @Html.ValidationSummary(true);

    <fieldset>
        <legend>Submit Your Request</legend>
        <div class="editor-label">@Html.LabelFor( Model => Model.CateogoriesList  )</div>
        <div class="editor-field">
            @Html.DropDownList("Category", new SelectList( Model.CateogoriesList ) )
        </div>
    </fieldset>
    <p><input type="submit" value="Send for RFP" /></p>
}

The problem is that I get the following error …

Compiler Error Message: CS0135: 'Model' conflicts with the declaration 'System.Web.Mvc.WebViewPage<TModel>.Model'

I saw the following clip make it work with the ViewBag … and I don’t understand why it won’t work when I include the list in the model.

http://www.pluralsight-training.net/microsoft/players/PSODPlayer.aspx?author=scott-allen&name=mvc3-building-data-i&mode=live&clip=0&course=aspdotnet-mvc3-intro

I have also seen that there are a lot of people that seem to have trouble with this simple task but in my googling … I haven’t come across anyone with the same error in trying to create a drop down list.

I would appreciate any suggestions that you or anyone may have. The only thing that I’ve come up with is that the SelectList constructor takes a parameter of type System.Collections.IEnumerable and what I’m trying to pass it is System.Collections.Generic.IEnumerable … or something close to it … and I don’t know how to cast it appropriately … though I don’t think I should have to … if it works with a viewbag as the means of transportation why doesn’t it work with the model as the means of transportation?

Thanks,

EDIT:======================

The problem was to do with the type of object the selectList constructor would accept. For some reason it wouldn’t accept a generic IQueryable but when I cast the result from the entity framework using the cast extension method toArray it suddenly worked.

So my model becomes …

public class Project
{
public Project()
{

    Riebro.RiebroEntities _db = new Riebro.RiebroEntities();
    CategoriesList = (from c in _db.Categories 
                    orderby c.Name
                    select c.Name).ToArray<string>();
}


[Display(Name = "Choose a category")]
public string[] CategoriesList;

}

note the .ToArray on the end of the query and then suddenly

@Html.DropDownList("Category", new SelectList(Model.CategoriesList))

works. Though I am going to point out the Model keyword here seems to be required.

  • 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-23T07:10:05+00:00Added an answer on May 23, 2026 at 7:10 am

    See your code, what’s that? that’s the reason cause the error.

      <div class="editor-label">@Html.LabelFor( Model => Model.CateogoriesList  )</div>
    

    correct one

          <div class="editor-label">@Html.LabelFor( Model => Model.CategoryId  )</div>
    
    @using (Html.BeginForm())
    {
    @Html.ValidationSummary(true);
    
    <fieldset>
        <legend>Submit Your Request</legend>
        <div class="editor-label">@Html.LabelFor(x=>x.CategoryId )</div>
        <div class="editor-field">
            @Html.DropDownList("Category", new SelectList(Model.CateogoriesList) )            
        </div>
    </fieldset>
    <p><input type="submit" value="Send for RFP" /></p>
    }
    

    Here is my simulation of your entity. I just add another CategoriesList2 which use to simulate the IQueryable object, but it’s still working.

        public class Project {
        public Project() {
            CategoryId = 0;
            Name = "";
            Description = "";
            //Categories = new Dictionary<int, string>();
    
            //Entities _db = new Entities(); //ef4
            //CateogoriesList = from c in _db.Categories
            //                  orderby c.Name
            //                  select c.Name;
            //IQueryable<string> categoriesList = (new string[] { }).AsQueryable();
            CateogoriesList = new string[] { "abc", "def", "hij", "klm" };
            CategoriesList2 = (new string[] { "abc", "def", "hij", "klm" }).AsQueryable();
        }
    
        public int CategoryId { get; set; }
    
        [Required]
        [DataType(DataType.Text)]
        [Display(Name = "Project Name")]
        public string Name { get; set; }
    
        [Required]
        [DataType(DataType.MultilineText)]
        [Display(Name = "Project Description")]
        public string Description { get; set; }
    
        public string[] CateogoriesList;
    
        public IQueryable<string> CategoriesList2;
    
    }
    

    Here is the view by using the IQueryable categories list

    @model MvcApplication3.Models.Project
    
    
    @using (Html.BeginForm())
    {
      @Html.ValidationSummary(true);
    
      <fieldset>
        <legend>Submit Your Request</legend>
        <div class="editor-label">@Html.LabelFor(x=>x.CategoryId )</div>
        <div class="editor-field">
            @Html.DropDownList("Category", new SelectList(Model.CategoriesList2) )            
        </div>
      </fieldset>
      <p><input type="submit" value="Send for RFP" /></p>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have been wrestling with the confines of ASP.NET trying to get JSONP working.
Okay... I've been wrestling this error for at least an hour now. I have
I've been wrestling with this seemingly simple re-direct task for hours now and for
I have been wrestling with this problem for quite some time now. I have
Have been learning ASP.NET (using C#) over the past few days. I have made
I've been wrestling with this for a while now. I have an app that
Ok so I have been wrestling with this and now thought I ask for
I have been wrestling with this for a few days and after tons of
This is a thought problem, and one I have been wrestling with for about
I have been working with SQL Server as a Developer a while. One thing

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.