I’ve been looking for hours the solution.
I’ve 3 models atm.
Priority:
using System;
using System.Collections.Generic;
namespace IssueReportManagementTest.Models
{
public class Priority
{
public int ID { get; set; }
public string Name { get; set; }
}
}
Category:
using System;
using System.Collections.Generic;
namespace IssueReportManagementTest.Models
{
public class Category
{
public int ID { get; set; }
public string Name { get; set; }
}
}
And the problem is that I’ve a Issue model and I want dynamic dropdowns from the other models.
Issue
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace IssueReportManagementTest.Models
{
public class Issue
{
[Key]
public int IssueID { get; set; }
public DateTime Added { get; set; }
public DateTime Modiefied { get; set; }
public virtual Category Category { get; set; }
public IEnumerable<Category> Categories { get; set; }
public virtual Priority Priority { get; set; }
public IEnumerable<Category> Priorities { get; set; }
[Required]
public string Title { get; set; }
[Required]
[DataType(DataType.MultilineText)]
public string Description { get; set; }
}
}
Is this correct? And what do I need in the Controller if I want to get dropdowns from priorities and categories. And yes they’re stored in the database.
This is what I have taken from my scenario, you can modify and adapt it to fit in with your code.
On my view I have a dropdown that displays the different banks.
My action method where I set the dropdown’s values from the database:
This is what my view model looks like (just a partial view):
Here is my Bank class:
This is my dropdown’s code in the view:
I hope this helps. It doesn’t do anything fancy, it just populates a dropdown. Shout if you need more clarification.