DmitryEfimenko / TwitterBootstrapMvc

Fluent implementation of ASP.NET-MVC HTML helpers for Twitter Bootstrap.
Apache License 2.0
223 stars 79 forks source link

FormGroup().DropDownList(string,string) #341

Open vanithav opened 9 years ago

vanithav commented 9 years ago

I can use the below which renders a drop down and populated the value automatically based on the foreignKey "ModuleTypeId". @Html.DropDownList("ModuleTypeId", "--Select--")

What is the equivalent in Twitter BMVC. I do not want to create a method or property that will return List(SelectListItem). How do i use the below method. FormGroup().DropDownList(string,string)

DmitryEfimenko commented 9 years ago

The BMVC's .DropDownList(string,string) is using the regular MVC's .DropDownList(string,string), under the hood. I'm not sure about the use of foreign keys to populate drop downs though.

vanithav commented 9 years ago

My model looks like this. public class Module { public int ID { get; set; }

    [StringLength(25)]
    [Required(AllowEmptyStrings = false, ErrorMessage = "Name is required.")]
    public String Name{ get; set; }

    [ForeignKey("ModuleType")]
    [Required(AllowEmptyStrings = false, ErrorMessage = "Module Type is required.")]
    public int ModuleTypeId { get; set; }

    public ModuleType ModuleType { get; set; }
}    

public class ModuleType
{
    public int ID { get; set; }

    [StringLength(25)]        
    public String Name { get; set; }
}

And when i use @Html.DropDownList("ModuleTypeId", "--Select--") in the view it loads the data from ModuleType Table.

But when i use @f.FormGroup().DropDownList("ModuleTypeId", "--Select--")

It throws me error. System.NullReferenceException: Object reference not set to an instance of an object.

DmitryEfimenko commented 9 years ago

is that EntityFramework that's doing it? I'm not familiar with it :/