Can I change the html name generated by Html.DropDownListFor?

前端 未结 9 1623
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 03:04

IDI am using the following code to create a drop down list:

 @for (var index = 0; index < Model.AdminSummaries.Count(); index++) 
            { 
            &         


        
9条回答
  •  心在旅途
    2021-02-05 03:38

    Like @Anar said in the comments;

    Actually, you can change the name attribute the same way as id, but instead of "name", use "Name". Surprisingly it works.

     @Html.DropDownListFor(x => Model.AdminSummaries[index].Status, 
    AdminStatusReference.GetAdminStatusOptions(), 
    new { id = string.Format("Status_{0}",index ), Name = "GiveName" });
    

提交回复
热议问题