【问题标题】:@if + lambda in an editor template@if + lambda 在编辑器模板中
【发布时间】:2011-08-22 02:05:11
【问题描述】:

我有些东西找不到正确的语法:

/Views/Shared/EditorTemplates/Component.cshtml

@model Website.Models.Component

<div class="editor-field">
    @if (x => x.Name == "")
    {
        @Html.EditorFor(x => x.Name)
        <button class="create">New</button>
    }
    else
    { 
        @Html.DisplayFor(x => x.Name)
        <button class="delete" value="@Model.Id">X</button>
    }
</div>

我希望意图很明确......我如何到达那里(这种事情很难用谷歌搜索)?

【问题讨论】:

    标签: asp.net-mvc-3 lambda razor editortemplates


    【解决方案1】:

    x =&gt; x.whatever 是一个 lambda 表达式;它创建一个委托。

    if 条件中,您需要一个普通表达式,可能使用Model 属性:

    @if (String.IsNullOrWhitespace(Model.Name)) {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 2014-11-27
      相关资源
      最近更新 更多