0

I have the following button:

<input type="button" id="btnNew" value="New Session" onclick="location.href='@Url.Action("NewSession","Telesales")'" />

how can I disable the button when my ViewBag is not null?

I have tried the following but it does not seem to work on input type button

<input type="button" id="btnNew" value="New Session" @((ViewBag.Session != null) ? "disabled" : "true") onclick="location.href='@Url.Action("NewSession","Telesales")'" />

2 Answers 2

3

Use Jquery instead:

$(document).ready(function(){
   if('@ViewBag.Session' != null)
   {
     $("#btnNew").attr('disabled','disabled');
   }
});

----------------------------------------------Or try this----------------------------------

<input type="button" id="btnNew" value="New Session" @((ViewBag.Session != null) ? "disabled" : "") onclick="location.href='@Url.Action("NewSession","Telesales")'" />
Sign up to request clarification or add additional context in comments.

Comments

0

Seems like my solution was working the only problem was the default css with MVC3 was not changing for a disable button so the button was disabled but looked like a normal button. Added css to solve this problem. Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.