Sitecore MVC,输入标记和条件表达式作为其值

时间:2014-04-24 16:52:01

标签: input lambda sitecore sitecore-mvc

将输入标记的value属性设置为条件语句时会出现一些奇怪的行为。我使用以下代码。

<input type="hidden" id="canAddAll" value="@(Model.WishList.Products != null && Model.WishList.Products.All(p => p.CanAdd))" />

&#34;值&#34;的预期结果对于输入标签将是&#34; True,&#34;但我只得到文字&#34;值。&#34;

<input type="hidden" id="canAddAll" value="value">

在查看编译源时,看起来它在这种情况下使用Tuple来创建value属性。期望的是值的简单Write()。

WriteAttribute("value", Tuple.Create(" value=\"", 272), Tuple.Create("\"", 382), Tuple.Create(Tuple.Create("", 280), Tuple.Create<System.Object, System.Int32>(Model.WishList.Products != null && Model.WishList.Products.All(p => p.CanAdd), 280), false)

为什么我会看到这种行为?

1 个答案:

答案 0 :(得分:0)

尝试利用Html.HiddenFor()。

有关完整说明,请参阅此处接受的答案:https://stackoverflow.com/a/18529322/435090

相关问题