I can't bind data to combobox, pls help me, it just show a blank combobox
My models
public class DanTocModels { [Key, Required, MaxLength(8)] public string MaDanToc{get;set;} public string TenDanToc { get; set; } }}
[controller] I used to Dapper(name of controller is: CommonController) and this below is my function
public IEnumerable get_all_dan_toc() { var rs = SqlMapper.Query(cn, "select * from tbl_dan_toc order by MaDanToc asc"); return rs; }
[view]
@model
@(Html.Infragistics().ComboFor(item => item.MaDanToc) .Width("270px") ..DataSource(Url.Action("/common/get_all_dan_toc")) .ValueKey("MaDanToc") .TextKey("TenDanToc") .DataBind() .Render() )
Hello Quang,
Thank you for contacting Infragistics!
I have modified your code in order to work, please refer to the attachment and let me know if you need further assistance.
Thank you for your answer Denis Georgiev, it's ok. But how to auto selected values when I have it.
And if I have country combobox how to cascading combobox state in asp mvc.
Refer to the sample attached.
Thank you for your answer, but how can I set selected item of combobox when load data from database
You can use .SelectedIndexes(int[]), where the method takes as argument array of integers.
Tk Denis Georgiev I can load all data for combobox but I have problem when set select item for combobox.
I can't used method .SelectedIndexes(int[]) it have error Error 9 'Infragistics.Web.Mvc.ComboWrapper' does not contain a definition for 'SelectedIndexes' and no extension method 'SelectedIndexes' accepting a first argument of type 'Infragistics.Web.Mvc.ComboWrapper' could be found.
And how to use Html.Infragistics().ComboFor() at mvc view, I have some code below
class PersonModels
{
string Fullname {get;set;}string CityID {get;set;}
...
}
if string someone person CityID has values 2 how to set selected item when I load all combobox city with city name & values
I use Dapper with return detail of someone person like this
[repository]
public List<PersonModels> Details(string id) { var p = new DynamicParameters(); p.Add("PersonID", id); IList<PersonModels> person = SqlMapper.Query<PersonModels>(cn, "proc_TS_ThongTinTuyenSinhLoadByPrimaryKey", p, commandType: CommandType.StoredProcedure).ToList<PersonModels>(); return person.ToList(); }
how to set selected item for combobox city from Person CityID value
Please provide sample replicating your issue.