-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Html.NameFor does not correctly generate name when field has two underscores #18913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you share a Fiddler trace showing the raw form post? |
With this class: public class Company2
{
public string Field__Name { get; set; }
public string OtherField { get; set; }
} and these values in form: This is the raw form post:
|
This is the HTML generated by ASP.NET Core: <div class="row">
<div class="col">
<div class="form-group">
<label for="Company2">Field__Name</label>
<input class="form-control" autofocus type="text" id="Company2" name="Company2" value="" />
<span class="text-danger field-validation-valid" data-valmsg-for="Company2" data-valmsg-replace="true"></span>
</div>
<div class="form-group">
<label for="Company2_OtherField">OtherField</label>
<input class="form-control" type="text" id="Company2_OtherField" name="Company2.OtherField" value="" />
<span class="text-danger field-validation-valid" data-valmsg-for="Company2.OtherField" data-valmsg-replace="true"></span>
</div>
</div>
</div> |
Values in the form POST: So this isn't a problem with parsing the form data on the server, it's a problem with generating the correct HTML to submit the form? Moving back to MVC. |
Yes. <input type="text" id="Company2" name="Company2" value="" /> instead of <input type="text" id="Company2_Field__Name" name="Company2.Field__Name" value="" /> |
@epic2001 thanks for contacting us. I'm not sure if this is a bug or it is a consequence of the current design. We will look into this and get back to you. |
Ok! Thank you! |
@stefanodelpero looks like asp-for has some specific code paths for properties that contain A fix for this could attempt to inspect the declaring type has a compiler generated attribute here:
In the meanwhile, there are a couple of options to workaround this: a) Use a different property name |
Hi. Thanks for contacting us. |
Fields with double underscore in name (I've to use a legacy system fields naming) disappear in Request.Form.
So, if I have an object like this:
And a cshtml page with:
The POST form action send the form value to the server but ASP.NET Request.Form didn't have the Field__Name field. Also the field is null in the OnPost parameter object.
Further technical details
The text was updated successfully, but these errors were encountered: