Home > Mobile >  Concatenate incrementing ID to @DropDownListFor id value
Concatenate incrementing ID to @DropDownListFor id value

Time:09-18

I'm trying to concatenate an dynamic numeric ID value to the @DropDownListFor HTMLHelper Id in my view.

@for (int i = 0; i < Model.AttributeValueList.Count(); i  )
{    
 ... Other code here 
<tr>
    <td class="DisplayFieldName">
        @Html.LabelFor(m => m.AttributeValueList[i].ListingTypeID)
    </td>
    <td class="DisplayFieldData" style="padding: 0px 0px 0px 5px;">
        @Html.DropDownListFor(m => m.AttributeValueList[i].ListingTypeID, Model.AttributeValueList[i].ListingTypes, new { @id = "listDropdown", @Name = "ListingTypeID", style = "width:207px;font-size:10pt;" })            
    </td>
</tr>
}

I can add it in the regulare HTML like so.

<tr class="@("listingOption-"   Model.AttributeValueList[i].ItemReschedualeOptionID)">

but when I try and add it inline with the HtmlHelper it errors out. Maybe I dont have the correct syntax.

@Html.DropDownListFor(m => m.AttributeValueList[i].ListingTypeID, Model.AttributeValueList[i].ListingTypes, new { @id = "listDropdown-"   ADD ID HERE, @Name = "ListingTypeID", style = "width:207px;font-size:10pt;" })

Ive looked at other SO post and nothing seems to work.

Here is what I've tried.

@id = "listDropdown-"   Model.AttributeValueList[i].ItemReschedualeOptionID,
@id = "@("listDropdown-"Model.AttributeValueList[i].ItemReschedualeOptionID)",
@id = "listDropdown-@(Model.AttributeValueList[i].ItemReschedualeOptionID)",

CodePudding user response:

Here is the correct syntax to concatenate to values in HTMLHelpers

@id = "listDropdown-" @Model.AttributeValueList[i].ItemReschedualeOptionID,
  • Related