Closed MCFHTAGENTS closed 5 years ago
Thanks for contacting us, @MCFHTAGENTS. @NTaylorMullen, is the behavior described here by design?
As you will see the value attribute is not being set for the first two but is present in the POCO object Customer (which is a POCO object of type CustomerCreate - all mine not MVC)
How are you setting LastName? Via controller? Form post?
Both in a way!
The form starts off as a view served from a HttpGet method on a controller. At this point Customer is null.
The user then submits the form a number of times (think of a wizard design pattern) incrementing a page counter passed back and forth as a hidden value. As they navigate through (effectively, create a booking, enter some key customer attributes, searching for an existing customer and if found direct that this record be used otherwise create a new one). In the use case here we have searched for a record and are creating a new one so the Customer record is populated with a skeleton record in the controller that is not persisted to the database at that point but used to pass the values to the view.
Thanks Mark
@MCFHTAGENTS could you provide a small repro without a database?
The attached zip file creates the output on my machine as presented by the attached image
@MCFHTAGENTS you're not @addTagHelper
ing the Mvc.TagHelpers so the input tag helper isn't running. For example, if you view source:
Note the asp-for is still in the output.
However, if at the top of your file you add @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Everything works as expected:
I have the following CSHTML:
which is rendered as:
Customer is defined as
public CustomerCreate Customer { get; set; }
and CustomerCreate, partially, as
As you will see the value attribute is not being set for the first two but is present in the POCO object Customer (which is a POCO object of type CustomerCreate - all mine not MVC)
There are no Editor Templates in play for strings.
This is in MVC Core 2.1.6
Has anyone any ideas?
Thanks Mark