I need to modify the display of elements in my razor view depending on the value of a variable that's in my model.
What I have is Model.PartitionKey which is a six character string. I need to code an if statement that will check if the 3rd and 4th characters of this string are "00".
Here's what I have so far:
@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>
}
The problem is that it there is an error message on line starting with @if on the 3rd character "f" saying "unexepected if keyword after the @ character".
Note that I have @ characters before the if in the first block of code. However it is just in the second block of code that it complains.