I am trying to conditionally disable fields in a grid popup editortemplate based on a value in the passed in Model. The value is correct in the model if I use an Html helper like a hidden field, but if I try to access it using razor code it is not there. I assume this has to do with the order of how things are loading but I'mm not sure how to fix it. Here is the editortemplate code:
When I view the source I can see that the hidden for Model.Status has the correct value but when I try to set the razor variable so I can use it to display the fields disabled, it does not have the value at all.
What am I missing?
@model PASSAdmin.ViewModels.ResourceReviewer.ResourceReviewViewModel
@{
bool disabled = true;
if (Model.Status == "BLREV")
{
disabled = false;
}
}
@Html.HiddenFor(model => model.Beamline_Request_ID, Model.Beamline_Request_ID)
@Html.HiddenFor(model => model.Status, Model.Status)
<
div
class
=
"editor-container"
style
=
"width:700px;"
>
<
p
>Please provide your recommendation of the experiment described in this Beam Time Request with regard to feasibility and safety.</
p
>
<
div
>
<
div
class
=
"editor-label"
>
@Html.Label("Approve")
</
div
>
<
div
class
=
"editor-field"
>
@if (disabled)
{
@Html.RadioButtonFor(model => model.Refused_By_Beamline, "N", new { disabled = true })
}
else
{
@Html.RadioButtonFor(model => model.Refused_By_Beamline, "N")
}
</
div
>
<
div
class
=
"editor-label"
>
@Html.Label("Deny")
</
div
>
<
div
class
=
"editor-field"
>
@if (disabled)
{
@Html.RadioButtonFor(model => model.Refused_By_Beamline, "Y", new { disabled = true })
}
else
{
@Html.RadioButtonFor(model => model.Refused_By_Beamline, "Y")
}
</
div
>
</
div
>
<
br
class
=
"clear"
/>
<
br
/>
<
br
/>
<
p
>By selecting Approve you are signifying the Experiment is feasible and can be performed safely on the indicated Beamline. If you select to Deny any of the above, please provide an explanation in the Comments area below. In addition to any specific comments, it is suggested you make note of any particular beamline equipment to be used during this experiment. Other staff may not have access to the full proposal information, but will have access to these comments.</
p
>
@*
<
div
class
=
"editor-label"
>
@Html.Label("Comments")
</
div
>
<
div
class
=
"editor-field"
>
@Html.EditorFor(model => model.Refused_By_Beamline, "N")
@Html.ValidationMessageFor(model => model.Refused_By_Beamline)
</
div
>
*@
<
p
>Note: comments entered here are visible to the Principal Investigator</
p
>
</
div
>
When I view the source I can see that the hidden for Model.Status has the correct value but when I try to set the razor variable so I can use it to display the fields disabled, it does not have the value at all.
What am I missing?