Skip to content

About Category Drop Down List #1

@MarsWangyang

Description

@MarsWangyang

Hi,

In /Controller/Models/Transaction.cs, this code below could make drop-down list of Category breaks if you don't choose any category. I know we can set range in the Transaction Model, but it is still a choice to choose.
Is there any way to improve that from AddOrEdit.cshtml side? cuz I know you remain CategoryId=0 for new category However, you insert a new CategoryId=0 in the model which makes it become a choice to choose.

       [NonAction]
        public void PopulateCategories()
        {
            var CategoryCollection = _context.Categories.ToList();
            Category DefaultCategory = new Category() { CategoryId = 0, Title = "Choose a Category" };
            CategoryCollection.Insert(0, DefaultCategory);
            ViewBag.Categories = CategoryCollection;
        }

Origin display:
image

Expected display (default is CategoryId=1, and won't insert a CategoryId=0):
image

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions