简体   繁体   English

在aspx视图引擎中使用Viewbag的语法?

[英]syntax of using Viewbag in aspx view engine?

I know ViewBag is used in Razor view engine but not sure how to access viewBag's dynamic properties in aspx view engine. 我知道ViewBag用于Razor视图引擎中,但不确定如何在aspx视图引擎中访问viewBag的动态属性。

As I want to put text inside Html.ValidationSummary() through Viewbag I am using the following syntax but getting error "has no applicable method named 'ValidationSummary' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax." 当我想通过Viewbag将文本放入Html.ValidationSummary()时,我在使用以下语法,但出现错误“没有名为'ValidationSummary'的适用方法,但似乎具有该名称的扩展方法。无法动态调度扩展方法。考虑转换动态参数或在不使用扩展方法语法的情况下调用扩展方法。”

Syntex: 西尔文特克斯:

<%= Html.ValidationSummary(ViewBag.ValidationSummary)%>

It is complaining because ValidationSummary has no single parameter overload that takes a parameter of type dynamic ; 抱怨是因为ValidationSummary没有单个参数重载,而该参数重载了dynamic类型的参数。 that is what ViewBag properties are. 这就是ViewBag属性。 Cast the property to a string. 将属性转换为字符串。

<%= Html.ValidationSummary((string)ViewBag.ValidationSummary)%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM