我似乎无法使此代码工作.如何让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
statement:
<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>