I have a cshtml file that has the section of similar to below code below:
<div id="entries" class="records-table">
@if (Model.Entries != null)
{
foreach (var entry in Model.Entries)
{
@Html.Partia("../Partials/_PartialEntry", entry)
}
}
</div>
And in my _PartialEntry file I have code similar as below:
<input asp-for="SomeModelValue" />
<div class="@(Model.SomeModelValue == "Special":"hidden":string.Empty)">...</div>
The issue that I am having is for a given entry the SomeModelValue properties between asp-for="SomeModelValue"
and @Model.SomeModelValue
are not the same. The @Model.SomeModelValue
always returns the SomeModelValue
of the previous entry. I will try and provide an example below.
Lets say me Model.Entries had the values below:
[{SomeModelValue = "Special", ....},
{SomeModelValue = "SomeOtherValue", ....}
{SomeModelValue = "Special", ....},
{SomeModelValue = "SomeValue", ....},
{SomeModelValue = "Special", ....}]
Note: Just using being lazy it is C# List of objects where SomeModelValue is a string property.
And I was edit the _ParialEntry code to:
<input asp-for="SomeModelValue" />
<div>@Model.SomeModelValue</div>
<div class="@(Model.SomeModelValue == "Special":"hidden":string.Empty)">...</div>
The resulting html that gets generated is similar to:
<div id="entries" class="records-table">
...
<input value="Special" />
<div>{Special}</div>
<div {class="hidden"}>...</div>
...
<input value="SomeOtherValue" />
<div>Special{SomeOtherValue}</div>
<div class="hidden"{} >...</div>
...
<input value="Special" />
<div>SomeOtherValue{Expecting:Special}</div>
<div {lass="hidden"}>...</div>
...
<input value="SomeValue" />
<div>Special{SomeValue}</div>
<div class="hidden"{}>...</div>
...
<input value="Special" />
<div>SomeValue{Special}</div>
<div {class="hidden"}>...</div>
...
</div>
The expected result I have placed in {...} inother words SomeValue{Special} means I got SomeValue displayed but I expected to see Special.
I hope this give you an idea of what I am encounter, I don't seem to understand why this is happening any pointer would be helpful thank you.