GenesysStack.com
RSS

Blog posts tagged with 'html'

Disallow in prod: alert() and response.write debugging

JS still requires a lot of alert() debugging. A quickie technique to stop that code from bleeding into Dev/qa/prod:

Put this in your _layout.cshtml or window.onload:

        function isDebug() {

            return @(HttpContext.Current.IsDebuggingEnabled);

        }

 Then use in your code:

        if (isDebug) { alert("customers do not want to see this"); }

 

Beware isDebug() is global with this implementation.

Happy coding!

Did You Know that you can clear MVC TextboxFor default values?
If you like strongly-typed Views...the trick is the Value Html attribute. Not “value”, “Value”. For example: @Html.TextBoxFor(m => m.BirthDate, "{0:MM/dd/yyyy}", new { @id = "txtBirthDate", @class = "form-control BirthDate", @Value = Model.BirthDate == "01/01/1900" ? "" : Model.BirthDate.ToString(), @placeholder = "MM/DD/YYYY" })