2017-07-16 48 views
0

我在ASP.NET Core MVC Web App中构建了一个引用表单。我有一个包含报价要求的性能再加上一个列表QuoteItems动态多项目存储在报价一QuoteVM:在我看来,我已经添加了一个输入栏自动完成加引号项目时ASP.NET Core MVC视图显示列表中输入的值不正确

public class QuoteVM 
{ 
    public string Status { get; set; } 

    public QuoteItemVM NewQuoteItem { get; set; } 

    #region QuoteProperties 
    // Not relevant 
    #endregion 

    #region Company 
    // Not relevant 
    #endregion 

    #region Client 
    // Not relevant 
    #endregion 

    public List<QuoteItemVM> QuoteItems { get; set; } 

    public List<string> WorkItems = new List<string>(); 

    public List<string> UnitList = new List<string> 
    { 
     "lm", 
     "fm", 
     "dag", 
     "heild", 
     "stk", 
     "klst" 
    }; 
} 

一个报价项目已被选中,我的表单将虚拟机发布到我在控制器中的POST操作中,并再次返回QuoteVM,并将新报价项添加到QuoteItems列表中,该列表在发送到视图之前通过报价项目编号属性进行排序。调试时,我可以看到列表正在正确发送到视图,我也可以通过在段落中写出我的QuoteItems列表来验证。在这里,我已经添加了4个项目到我的报价,一切都按预期工作: Values are still correct

现在我们终于来到了这是,当我补充一点,有一些低的报价项目比我在我的表中的问题开始显示错误的价值观呈现表时,但该列表将是正确的,因为控制器是正确返回列表:

@{ // display values to check if they're correct 
    foreach (var item in Model.QuoteItems) 
    { 
     <p>@item.Number - @item.Description - @item.Unit</p> 
    } 
} 

<tbody> 
@{ // the goal is to display them correctly here 
    for (int i = 0; i < Model.QuoteItems.Count(); i++) 
    { 
    <tr> 
     <td><input type="checkbox" class="i-checks" name="input[]"></td> 
     <td><input asp-for="QuoteItems[i].Number" class="form-control text-center input-sm" /></td> 
     <td><input asp-for="QuoteItems[i].Description" placeholder="Verkþáttur" class="form-control input-sm" /></td> 
     <td><input asp-for="QuoteItems[i].Quantity" placeholder="Magn" class="form-control text-center input-sm jsQuantity calculate" /></td> 
     <td><input asp-for="QuoteItems[i].Unit" placeholder="Eining" class="form-control text-center units input-sm" /></td> 
     <td><input asp-for="QuoteItems[i].UnitPrice" placeholder="Einingarverð" class="form-control text-center input-sm jsUnitPrice calculate" /></td> 
     <td><input asp-for="QuoteItems[i].TotalPrice" class="form-control text-center input-sm jsTotalPrice" /></td> 
     <td><input asp-for="QuoteItems[i].TotalPriceVAT" class="form-control text-center input-sm jsTotalPriceVAT" /></td> 
    </tr> 
    } 
} 
</tbody> 

有没有人来看: Where things start to go south...

的我认为是相关零部件陷入类似的问题或知道什么可能导致这个?

回答

0

我的解决方案是在模型之前添加ModelState.Clear()来查看。