c# - asp-for="Property" and @Model.Property values are not the same for the same object -


i have cshtml file has section of similar 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 _partialentry file have code similar below:

<input asp-for="somemodelvalue" /> <div class="@(model.somemodelvalue == "special":"hidden":string.empty)">...</div> 

the issue having given entry somemodelvalue properties between asp-for="somemodelvalue" , @model.somemodelvalue not same. @model.somemodelvalue returns somemodelvalue of previous entry. try , provide example below.

lets me model.entries had values below:

[{somemodelvalue = "special", ....},   {somemodelvalue = "someothervalue", ....}   {somemodelvalue = "special", ....},  {somemodelvalue = "somevalue", ....},  {somemodelvalue = "special", ....}] 

note: using being lazy c# list of objects somemodelvalue string property.

and edit _parialentry code to:

<input asp-for="somemodelvalue" /> <div>@model.somemodelvalue</div> <div class="@(model.somemodelvalue == "special":"hidden":string.empty)">...</div> 

the resulting html gets generated 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 have placed in {...} inother words somevalue{special} means got somevalue displayed expected see special.
hope give idea of encounter, don't seem understand why happening pointer helpful thank you.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -