2011-05-10 35 views
1

我有东西,我无法找到正确的语法:@if +拉姆达在编辑器中模板

/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> 

希望目的很明确......我如何到达那里(对于这类事情很难谷歌)?

回答

2

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

内的if条件,你需要一个正常的表达,可能是使用Model属性:

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

啊......我有机会获得模型。完善。谢谢! – ekkis 2011-05-10 02:06:44