locked
string doesnot contain definition for removeAttr and no extension method 'removeAttr' RRS feed

  • Question

  • User-1355965324 posted

    I am trying to enable and disable the button depends the value in ViewBag variable. In Controller. But the following error is coming when I give 

    string doesnot contain definition for removeAttr   and no extension method 'removeAttr'. Please help

    ViewBag.IsBtnEnbaled = "N";

    <div class="col-sm-5">
                                <div class="center-block  col-sm-6">
                                    <button type="submit" class="btn btn-primary form-control" id="btnSave" name="submit" disabled>Save</button>
                                </div>
    </div>
    <script type="text/javascript">
     @if (ViewBag.IsBtnEnbaled =="Y")
          {
               $("button[name='submit']").removeAttr('disabled');
    
          }
    </script>

    Monday, November 16, 2020 4:32 PM

Answers

  • User-474980206 posted

    why do this client side? just code correctly on the server:

    <button 
       type="submit" 
       class="btn btn-primary form-control" 
       id="btnSave" 
       name="submit" 
       @(ViewBag.IsBtnEnabled == "Y" ? "" : "disabled")
    > Save</button>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 16, 2020 5:41 PM

All replies

  • User475983607 posted

    The syntax is incorrect.

    <script>
        if ("@ViewBag.IsBtnEnbaled" =="Y")
        {
            $("button[name='submit']").removeAttr('disabled');
        }
    </script>

      

    Monday, November 16, 2020 5:28 PM
  • User-474980206 posted

    why do this client side? just code correctly on the server:

    <button 
       type="submit" 
       class="btn btn-primary form-control" 
       id="btnSave" 
       name="submit" 
       @(ViewBag.IsBtnEnabled == "Y" ? "" : "disabled")
    > Save</button>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 16, 2020 5:41 PM
  • User-1355965324 posted

    Many Thanks Bruce

    Tuesday, November 17, 2020 6:57 AM