我在下面得到這個錯誤。mvc4 System.InvalidOperationException
Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
異常在SUBSTRING()函數
<td class="hidden-desktop">@Html.DisplayFor(modelItem => item.isim.Substring(0,10).ToString());</td>
<td class="hidden-phone hidden-tablet">@Html.DisplayFor(modelItem => item.isim)</td>
我想根據屏幕尺寸diisplay同一文本的短期和長期的版本低於觸發。我做錯了什麼來獲取錯誤信息?或者我應該如何正確使用substring()?
Html.DisplayFor期望您的模型中有成員(屬性或字段),Substring不是模型的成員。您可能需要添加一個屬性,比如ShortISIM,它返回要輸出的較短版本的字符串。 – emgee