dotnet / dotnet/aspnetcore

Mvc SelectTagHelper name property can't working

Open
#63,382 1 comment 0 reactions 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Our requirement need to model binding input names as format as follow to avoid index gap:
_CustomerModel.Contacts[0756264e-600b-47e4-8918-3176d8c57dcb].Name=foo&
CustomerModel.Contacts[0756264e-600b-47e4-8918-3176d8c57dcb].Gender=Male&
&CustomerModel.Contacts.index=0756264e-600b-47e4-8918-3176d8c57dcb_

need to bind with name "CustomerModel.Contacts[Xxx].Gender" in our requirement rathor than CustomerModel.Contacts[0].Gender there,
I tried to set SelectTagHelper name="CustomerModel.Contacts[@idx].Name" there but not working.
```

Male
Female

```
InputTagHelper set name working there

```

```
so set name property in SelectTagHelper will not working when asp-for setted is a bug need to fix? thanks.

the code block as follow
```

...
@for (int index = 0; index < Model.CustomerModel.Contacts.Count; index++)
{
string idx = Guid.NewGuid().ToString();





@Html.ValidationMessage($"CustomerModel.Contacts[{@idx}].Name", new { @class = "validation-error" })


@* issue there *@
@Html.DropDownList($"CustomerModel.Contacts[{index}].Name", new SelectList(genders), new { @class = "form-control", name = $"CustomerModel.Contacts[{idx}].Gender" })

@Html.ValidationMessage($"CustomerModel.Contacts[{@idx}].Gender", new { @class = "validation-error" })


Delete

```

}
...

### Expected Behavior
SelectTagHelper render as:
```

Male
Female

```

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

8.0

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.