C# 使用Razor在Cshtml页面上使用条件语句

C# 使用Razor在Cshtml页面上使用条件语句,c#,asp.net-mvc,asp.net-mvc-4,razor,C#,Asp.net Mvc,Asp.net Mvc 4,Razor,我似乎无法让这个代码正常工作。如何获取要在屏幕上显示的文本框?我尝试的东西都不管用 @foreach (var items in Model.Pages[0].Items){ <div class="form-group"> <label for="pageType" class="col-sm-2 control-label">Label:</label> <div class="col-sm-10"> @{ string

我似乎无法让这个代码正常工作。如何获取要在屏幕上显示的
文本框?我尝试的东西都不管用

@foreach (var items in Model.Pages[0].Items){
<div class="form-group">
<label for="pageType" class="col-sm-2 control-label">Label:</label>

<div class="col-sm-10">
    @{
       string htmlOutput;
       if (items.PageItemTypeId == (int)HOD.Controllers.PageItemTypesEnum.MainTextContent)
       {
           htmlOutput = @Html.TextBoxFor(x => items.PageContent, new { @class = "form-control", @placeholder = "Content" }).ToHtmlString();
           Response.Write(htmlOutput);
       }
  <input type="hidden" id="pageTypeId" />
</div>
</div>
@foreach(Model.Pages[0].items中的变量项){
标签:
@{
字符串htmlOutput;
if(items.PageItemTypeId==(int)HOD.Controllers.PageItemTypesEnum.MainTextContent)
{
htmlOutput=@Html.TextBoxFor(x=>items.PageContent,新的{@class=“form control”,@placeholder=“Content”});
Response.Write(htmlOutput);
}
您应该创建一个:


@if(items.PageItemTypeId==(int)HOD.Controllers.PageItemTypesEnum.MainTextContent)
{
@TextBoxFor(x=>items.PageContent,新的{@class=“form control”,@placeholder=“Content”});
}

谢谢,有一段时间我回到幼儿园,没有检查数据。语法有效
<div class="col-sm-10">
    @if (items.PageItemTypeId == (int)HOD.Controllers.PageItemTypesEnum.MainTextContent)
    {
        @Html.TextBoxFor(x => items.PageContent, new { @class = "form-control", @placeholder = "Content" });
    }
  <input type="hidden" id="pageTypeId" />
</div>