How to use ternary operator in razor view

asp.net-mvc-4razor

I am using MVC 4 razor view . here i want to disable the textboxfor if the "ERAGOGType" is "None" else if the value is not "None" then enable it

My view razor code

@{
if ((Model.ERAGOGType == "None"))
{   
    @Html.LabelFor(model => model.ERAGOGCode)
    @Html.TextBoxFor(model => model.ERAGOGCode, new { @disabled = true })
}
else
{
    @Html.LabelFor(model => model.ERAGOGCode)
    @Html.TextBoxFor(model => model.ERAGOGCode)
}}

How can i achieve this by using a ternary operator ? plz help

Thanks in advance

Best Answer

You could try:

@Html.TextBoxFor(model => model.ERAGOGCode, Model.ERAGOGType == "None" ? new { @disabled = true } : null)