The following piece of code is not disabling the html button. I am using MVC3 razor . Can anyone point out where I am going wrong
@{
bool disablebutton = bool.Parse(ViewData["Disablebutton"].ToString());
}
$(document).ready(function () {
if (@disablebutton) {
$('#abc').attr('disabled', 'disabled');
}
});
Based on your comment in your question, there’s your problem: “True” is not valid Javascript. It has to be
trueall lowercase. Look at your JS error console and I’m sure you’ll have an error.You can do
if (@disablebutton.ToLower())The above is just one way of resolving your issue. You need to be careful when mixing server-side with client-side.