-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesquestion
Description
Describe the bug
Html.HiddenFor(m => m.Property) won't use htmlAttributes value for value attribute even if m.Property is null and/or there are no such key in ModelState.
To Reproduce
Model:
public class ViewForm
{
[Required]
public Guid? FormId { get; set; }
}View:
...
@Html.HiddenFor(m => m.FormId, new Dicitonary<string, object> { { "value", Guid.NewGuid() } })
...FormId is not initialized, so it is null.
Actual result:
<input data-val="true" data-val-required="The FormId field is required." id="FormId" name="FormId" type="hidden" value>Expected result:
<input data-val="true" data-val-required="The FormId field is required." id="FormId" name="FormId" type="hidden" value="2c0d312b-b21b-4ee3-9b8a-5b8790632f6d">Documentation for HiddenFor clearly states:
Returns an element of type "hidden" for the specified expression. Adds a "value" attribute to the element containing the first non-null value found in: the ModelState entry with full name, the expression evaluated against Model, or the htmlAttributes dictionary entry with key "value". See NameFor(Expression<Func<TModel,TResult>>) for more information about a "full name".
Further technical details
- ASP.NET Core 2.1.* nuget packages @ net472
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesquestion