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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:43:10+00:00 2026-06-04T03:43:10+00:00

What I want to do is to populate SelectList with categories from a categories

  • 0

What I want to do is to populate SelectList with categories from a categories repository.
A little mockup http://mockupbuilder.com/App/15379.

What I have now is a controller:

[HandleError]
public class ProductController : Controller {
    private IRepository<Product> exhibitions;
    private IRepository<Category> categories;
    private readonly Int32 PageSize = 18;

    // ctor ...

    [HttpPost]
    public ActionResult Create(Product product, Guid categoryId) { 
        // validation ...
        // properties setting ...            
        product.Category = categories.Get(categoryId);
        return View(product);
    }

Category class is like this:

public class Category : AbstractEntity<Category> {
    public String Title { get; set; }
    public String Description { get; set; }
}

How do I populate a SelectList? How do I make this using JSON?

Thanks!

  • 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-04T03:43:11+00:00Added an answer on June 4, 2026 at 3:43 am

    You can put the List in viewbag and render it using aspx code. Something like below:

    [HttpGet]
    public ActionResult Create() // your create page render action
    {
        Viewbag.CategoryList = categories.GetAll(); //put it into viewbag
    
        return View();
    }
    

    And in your view page, something like this:

    <select name="categoryId"> <%-- use name attribute to bind action parameters and model --%>
    <%foreach (Category item in Viewbag.CategoryList)
      { %>
    <option value="<%=item.Id %>"><%=item.Title %></option>
    <% } %>
    </select>
    

    If you want to populate the categories via json.
    You have to write a new action in your category controller like:

    public class CategoryContrller : Controller{
        ....
    
        [HttpGet]
        public ActionResult GetAll()
        {
            var categories = categories.GetAll(); //put it into viewbag
    
            return Json(categories, JsonRequestBehavior.AllowGet);
        }
    }
    

    And in your page’s js logic use ajax to call it and handle the result.

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

Sidebar

Related Questions

I want to populate a list from my database. I have the following code:
I want to populate a table form a MYSQL database. I have defined the
I want to populate a drop down menu with a column from a MySQL
I have a view that creates and populates a Selectlist. I want to bind
I want to populate data from database in to a table view in grouped
I want to populate a TableView with data from a database and, when tap
I have a DropDownList populated with a SelectList generated from (an anonymous type) that
I have a dropdown in my CreateDocumentTemplate ciew <%=Html.DropDownList(Part, (SelectList)ViewData[Part])%> which is populated from
I have a situation where I want to associate multiple values from one table
i want populate data in parent window from a popup window. can any one

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.