[英]Getting error in HtmlHelper/Razor in asp.net mvc-5
我創建了一個cshtml文件。 當我在visual studio中運行/構建解決方案時,解決方案構建良好甚至功能明智(據我所知)一切似乎都在工作但我在Visual Studio錯誤窗口中看到一些錯誤。 有人可以指導我為什么看到這些錯誤。
@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)'的類型參數。 嘗試顯式指定類型參數。
你的model.CreditDetails.CreditCard
有一個很難為MVC model.CreditDetails.CreditCard
的類型。
嘗試將其轉換為普通類型,或指定應直接使用的類型。
@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" })
這就是錯誤試圖告訴你的,但我不知道是否有更好/完美的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.