C# 在asp.net mvc-5中获取HtmlHelper/Razor中的错误
我已经创建了一个cshtml文件。当我在VisualStudio中运行/构建解决方案时,解决方案构建得很好,甚至在功能方面(据我所知),一切似乎都正常,但我在VisualStudio错误窗口中看到一些错误。有人能告诉我为什么我会看到这些错误吗C# 在asp.net mvc-5中获取HtmlHelper/Razor中的错误,c#,asp.net,razor,asp.net-mvc-5,html-helper,C#,Asp.net,Razor,Asp.net Mvc 5,Html Helper,我已经创建了一个cshtml文件。当我在VisualStudio中运行/构建解决方案时,解决方案构建得很好,甚至在功能方面(据我所知),一切似乎都正常,但我在VisualStudio错误窗口中看到一些错误。有人能告诉我为什么我会看到这些错误吗 @if (Utils.IsCC) { <div class="CC"> <div class="form"> @Html.LabelFor(model => model.Cred
@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>
}
@if(Utils.IsCC)
{
@LabelFor(model=>model.CreditDetails.CreditCard,htmlAttributes:new{@class=“controllabel col-md-2 required”})
//红色蠕动出现在上面的整条线上
}
错误:
方法'System.Web.Mvc.Html.LabelExtensions.LabelFor(System.Web.Mvc.HtmlHelper,
System.Linq.Expressions.Expression>,System.Collections.Generic.IDictionary)'
无法从用法推断。尝试显式指定类型参数
您的
model.CreditDetails.CreditCard
的类型对于MVC来说很难识别
尝试将其转换为普通类型,或指定应直接使用的类型
@Html.LabelFor<string>(model => model.CreditDetails.CreditCard, htmlAttributes: new { @class = "control-label col-md-2 required" })
@Html.LabelFor(model=>model.CreditDetails.CreditCard,htmlAttributes:new{@class=“control label col-md-2 required”})
或
@Html.LabelFor(model=>model.CreditDetails.CreditCard,htmlAttributes:new{@class=“control label col-md-2 required”})
这就是错误试图告诉您的,但我不知道是否有更好/完美的解决方案。您的
模型。CreditDetails.CreditCard
的类型对于MVC来说很难识别
尝试将其转换为普通类型,或指定应直接使用的类型
@Html.LabelFor<string>(model => model.CreditDetails.CreditCard, htmlAttributes: new { @class = "control-label col-md-2 required" })
@Html.LabelFor(model=>model.CreditDetails.CreditCard,htmlAttributes:new{@class=“control label col-md-2 required”})
或
@Html.LabelFor(model=>model.CreditDetails.CreditCard,htmlAttributes:new{@class=“control label col-md-2 required”})
这就是错误试图告诉您的,但我不知道是否有更好/完美的解决方案