簡體   English   中英

使用Razor在Cshtml頁面上的條件語句

[英]Conditional Statements on Cshtml page with Razor

我似乎無法使此代碼工作。 如何讓TextBoxFor顯示在屏幕上? 我沒有嘗試任何作品。

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

你應該創建一個Razor @if語句

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM