Ad

If Property At Session Not Null Or Default Value, Run/print Javascript Razor ASP.NET MVC

- 1 answer

How to print javascript when I accessing model from session and property value not empty at Razor?

This is my code:

@{ ARM.Models.LanIDModel lanIdModel = (LanIDModel)HttpContext.Current.Session["sessLanIDModel"]; }}


@if(lanIdModel.LanID!=0 && lanIdModel.Name != string.Empty &&  !string.IsNullOrEmpty(lanIdModel.Email)){
           @Html.Raw("$('.input-switch-disabled').removeAttr('disabled');");
        }

And when I run on browser, I got this:

 @if(lanIdModel.LanID!=0 && lanIdModel.Name != string.Empty && !string.IsNullOrEmpty(lanIdModel.Email)){
Line 98:            @Html.Raw("$('.input-switch-disabled').removeAttr('disabled');");
Line 99:         }

Is it able to do?

Ad

Answer

Wrap your javascript in script tags.

@Html.Raw("<script>$('input-switch-disabled').removeAttr('disabled');</script>");
Ad
source: stackoverflow.com
Ad