xml - HTML.TextAreaFor ASP.NET MVC“模板只能用于字段访问”
问题描述
这行代码导致以下错误。
代码:
@Html.TextAreaFor(model => XDocument.Parse(model.TramaDetalle).ToString(),
new { @class = "form-control", @readonly = "readonly", @title = "Detalle" , @style = "height: 320px;resize: none;" })
错误:
模板只能与字段访问、属性访问、一维数组索引或单参数自定义索引器表达式一起使用。
这可以重写还是我不能这样做?
解决方案
你可以这样做。
@var parsedTramaDetalle = XDocument.Parse(model.TramaDetalle).ToString();
和
@Html.TextAreaFor(model => model.TramaDetalle,
new { @class = "form-control",@value=parsedTramaDetalle, @readonly = "readonly", @title = "Detalle" , @style = "height: 320px;resize: none;" })
另一种方法是在控制器中解析它并直接使用Htmlhelper
:
@Html.TextAreaFor(model => model.ParsedTramaDetalle,
new { @class = "form-control",@value=parsedTramaDetalle, @readonly = "readonly", @title = "Detalle" , @style = "height: 320px;resize: none;" })
推荐阅读
- reactjs - 在 NextJS 中使用具有高阶函数的持久布局
- amazon-web-services - 为 AWS Java Lambda 函数创建 docker 映像
- phoenix-framework - 算术表达式中的错误参数(小数)
- python - 在python中找到给定的正则表达式模式
- python - 熊猫从列中剥离字符串
- xml - XSLT 比较值并检查结果
- azure-container-instances - 我没有收到来自 azure 容器实例的任何日志,而日志位于容器选项卡中
- python - 我想阅读aa excel中的所有工作表并将其作为一个数据框
- html - 瞄准所有
- 除了 CSS 中的一个元素
- javascript - 如何将 ViewBox svg 转换为零初始坐标?