gpt4 book ai didi

c# - 我的 MVC3 razor View 中的 if 语句存在问题

转载 作者:行者123 更新时间:2023-11-30 19:30:05 25 4
gpt4 key购买 nike

我需要根据模型中变量的值修改 razor View 中元素的显示。

我拥有的是 Model.PartitionKey,它是一个六字符的字符串。我需要编写一个 if 语句来检查该字符串的第 3 个和第 4 个字符是否为“00”。

这是我目前所拥有的:

@using (Ajax.BeginForm(
action,
"Contents",
null,
new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = success,
OnFailure = "ajaxOnFailure"
}, new { @id = "dialogForm", @class = "content ui-widget dialog-admin" }))
{

<div class="float-left">
@Html.LabelFor(model => model.Status)
@if (action == "Edit" || action == "Create") {
@Html.DropDownList("Status", null, new { @class="drop-down", id = "dialogStatus", style="width: 120px" })
}
else
{
@Html.TextBox("Status", (string)ViewBag.Status, new { @readonly = true })
}
</div>

@if ( Model.PartitionKey.Substring(2,2) == "00") {
<div class="float-left">
Html.LabelFor(model => model.Link)
if (action == "Edit" || action == "Create") {
Html.TextBoxFor(model => model.Link, new { size = 25 })
} else {
Html.TextBoxFor(model => model.Link, new { size = 25, @readonly = true })
}
</div>
}

问题是它在第 3 个字符“f”上以 @if 开头的行上有一条错误消息说“unexepected if keyword after the @ character”。

请注意,我在第一个代码块中的 if 之前有 @ 字符。然而,它只是在第二个代码块中提示。

最佳答案

尝试

@using (Ajax.BeginForm(
action,
"Contents",
null,
new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = success,
OnFailure = "ajaxOnFailure"
}, new { @id = "dialogForm", @class = "content ui-widget dialog-admin" }))
{

<div class="float-left">
@Html.LabelFor(model => model.Status)
@if (action == "Edit" || action == "Create") {
@Html.DropDownList("Status", null, new { @class="drop-down", id = "dialogStatus", style="width: 120px" })
}
else
{
@Html.TextBox("Status", (string)ViewBag.Status, new { @readonly = true })
}
</div>

if ( Model.PartitionKey.Substring(2,2) == "00") {
<div class="float-left">
@Html.LabelFor(model => model.Link)
@if (action == "Edit" || action == "Create") {
@Html.TextBoxFor(model => model.Link, new { size = 25 })
} else {
@Html.TextBoxFor(model => model.Link, new { size = 25, @readonly = true })
}
</div>
}
}

关于c# - 我的 MVC3 razor View 中的 if 语句存在问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10063648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com