我创建了一个cshtml文件。当我在visual studio中运行/构建解决方案时,解决方案构建良好,甚至从功能上看(据我所知),一切似乎都正常,但我在Visual错误窗口中看到了一些错误。有人能指点我为什么我看到这些错误。
@if (Utils.IsCC)
{
<div class="CC">
<div class="form">
@Html.LabelFor(model => model.CreditDetails.CreditCard, htmlAttributes: new { @class = "control-label col-md-2 required" })
// Red squiggly comes in the entire line above
</div>
</div>
}错误:
无法从用法中推断方法'System.Web.Mvc.Html.LabelExtensions.LabelFor(System.Web.Mvc.HtmlHelper,System.Linq.Expressions.Expression>,System.Collections.Generic.IDictionary)的类型参数。尝试显式指定类型参数。
发布于 2017-03-30 19:35:12
您的model.CreditDetails.CreditCard有一种很难重新适应MVC的类型。
尝试将其转换为普通类型,或指定应直接使用的类型。
@Html.LabelFor<string>(model => model.CreditDetails.CreditCard, htmlAttributes: new { @class = "control-label col-md-2 required" })或
@Html.LabelFor<ComplexObject>(model => model.CreditDetails.CreditCard, htmlAttributes: new { @class = "control-label col-md-2 required" })这就是错误试图告诉您的,但我不知道是否有更好的/完美的解决方案。
https://stackoverflow.com/questions/43126186
复制相似问题