我想根据Model中的isUpload变量过滤我的模型。
我的逻辑是如果Models.Docs项的isupload变量= true我想要显示按钮有'Sil'文本。否则如果isUpload variable = false我想要显示按钮有'GörselYükle文本。我可以提供这个吗?< / p>
我将模型foreach if子句设置为View.Everything okey Model.Docs为isUpload bool过滤。 我的代码在这里:
@if (Model.Data != null)
{
foreach (var item in Model.Data)
{
<table cellspacing="20" cellpadding="0">
<tr>
<td style="padding-right: 10px; vertical-align: middle">
<span>@item.doctype_desc</span>
</td>
<td>
@if (Model.Docs != null)
{
foreach (var item2 in Model.Docs)
{
<input class="uploadInput" id="@item.doctype_id" data-doctypeid="@item.doctype_id" style="display: none;" type="file" accept="image/* ">
if (item2.isUpload)
{
<input class="uploadButton" id="btnSave" type="button" value="Sil" data-doctypeid="@item.doctype_id" />
}
else
{
<input class="uploadButton" id="btnSave" type="button" value="Görsel Yükle" data-doctypeid="@item.doctype_id" />
}
}
}
</td>
</tr>
</table>
}
}
如果逻辑调试了正确的模型返回,这就是我的模型。
Controlller语法的详细信息:
//formData.Docs variable is my returned data from database.
// formTypes.Data is including all types of formdata.
foreach (var item in formData.Docs)
{
if (formtypesData.Data.Any(x => x.doctype_id == item.doctype_id))
{
item.isUpload = true;
}
else
{
item.isUpload = false;
}
}
model.Docs = formData.Docs;
#endregion
return View(model);