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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:41:11+00:00 2026-05-22T02:41:11+00:00

using (var db = new PNUBOOKIR.Models.KowsarSiteEntities()) { var q = (from m in db.GoodTypes

  • 0
using (var db  = new PNUBOOKIR.Models.KowsarSiteEntities())
        {
            var q = (from m in db.GoodTypes
                    select new
                    {
                        GroupCode = m.GroupCode,
                        Text = m.Text
                    }).ToList();

        }         

How I can set it in dropdownlist GroupCode as Value and Text as ItemText How I can do that in mvc 3.0 ?

Added :

        public ActionResult Index()
    {
        using (var db = new PNUBOOKIR.Models.KowsarSiteEntities())
        {
            var q = from m in db.GoodTypes
                    where !m.GroupCode.Equals(null) && !m.Text.Equals(string.Empty) && !m.Text.Equals(null)
                    select new
                    {
                        GroupCode = m.GroupCode,
                        Text = m.Text
                    };
            ViewData["list"] = q.ToList().Select(t => new SelectListItem()
                             {
                                 Text = t.Text,
                                 Value = t.GroupCode.ToString(),
                                 Selected = true
                             });
        }      
        return View();
    } 

  <div>
        @using (Html.BeginForm())
        {

            System.Collections.IEnumerable ien = (System.Collections.IEnumerable)ViewData["list"];
            Html.DropDownList("lstGoodTypes", new SelectList(ien, "Value", "Text"));

        }
    </div>

it works but there is no dropdownlist at the result there is no error and there is not dropdownlist it is cool.

  • 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-22T02:41:12+00:00Added an answer on May 22, 2026 at 2:41 am

    In your controller you can do:

    ViewData["list"]=q.Select(t=>new SelectListItem
                                     {
                                         Text=t.Text,
                                         Value=t.GroupCode,
                                         Selected=<Here you have to return a boolean to decide if the item is selected>
                                      });
    

    And in your view you can add this to a form:

    @Html.DropDownList("list")
    

    In your form’s post method you’ll need to have a parameter named list of the same type as GroupCode and treat it accordingly.

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

Sidebar

Related Questions

I am opening a new window from a button using var myWindow = window.open(...).
can I do something like this: using (var scope = new TransactionScope()) { using
I read a set of data from database first Insert a new record using
This can't compile: void Foo() { using (var db = new BarDataContext(ConnectionString)) { //
The following code: using (var db = new Entities()) { db.Blogs.First().Posts.Skip(10).Take(5).ToList(); } Will generate
using (var client = new WebClient()) { html = client.DownloadString(some_string); //do something html =
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
Given the following code: using (var client = new WebClient()) { string url =
If I create a socket using var socket = new UdpClient(0,AddressFamily.InterNetwork); How do I
Let's have an example: using (var someObject = new SomeObject()) { var someOtherObject =

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.