After click hyperlink ( asp-controller & asp-action ), then others hyperlink is disable to prevent another

Jerry Lipan 916 Reputation points
2022-01-17T23:45:46.1+00:00

Hi,

My ASP.NET Core Hyperlink with CSS as following,

165871-10012022-01.png

I want to do this,

" After click any hyperlink ( asp-controller & asp-action ), then others hyperlink is disable. How to do that ? "

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,188 questions
{count} votes

Accepted answer
  1. Zhi Lv - MSFT 32,016 Reputation points Microsoft Vendor
    2022-01-18T01:49:33.407+00:00

    Hi @Jerry Lipan ,

    You can refer to the following sample to disable the hyperlink, it uses Bootstrap style and JQuery (the Bootstrap and JQuery reference have been added in the _Layout page):

    <div>   
        <a href="#" class="btn btn-info" role="button">Yes, I'M RESPONSE TO THIS INCIDENT</a>  
        <a href="#" class="btn btn-info" role="button">INCIDENT SOLVE</a>  
    </div>  
    

    JQuery code:

    <script>  
        $(function(){  
           $(".btn").click(function(){  
              event.preventDefault();   //prevent the hyperlink defaule navigation event.  
    
              //find another button exclude current click one, and then disable them  
              $(".btn").not(this).each(function(index, item){   
                  $(item).addClass("disabled"); //add the disabled class and disable the button.  
                    
                  //Once the hyperlink is disabled change the css style.  
                  $(item).removeClass("btn-info");  
                  $(item).addClass("btn-secondary");  
              });  
           });  
        })  
    </script>  
    

    The result as below:

    165834-1.gif


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Jerry Lipan 916 Reputation points
    2022-01-18T03:14:08.41+00:00

    Hi @Zhi Lv - MSFT

    Your explanation was great. Let's say this
    165924-18012022-002.png

    produces html as following,

       <a class="btn btn-info" role="button" href="/Incident/OpenIncidentFromIncidentListResponse/CfDJ8Hq-WaqbvO1LgvkM3H_V86HapN6hTNDlgi-2Z8ffa5bgqAgURJUWY3aM76R0hcDY1CmTypAU6WNPkl3mg8xBWbxLGbetw1huDzwr4PHyPsZjI6dkIT1Jv5bn5mdED12aTw?IncidentNo=CfDJ8Hq-WaqbvO1LgvkM3H_V86EWRhkKbUtHxTIKzC-K0LmFwf-fOqVqe5PTZdiWo0XMRNjrF_2fq0dD2AUODqRvADAPSU4AB68MRcMW6qFKPC7qOXNCTch-4R3TRq77CvThT3RRrkdhA3UqbWSH32BmTFs">Yes, I'm response to this incident</a>  
      
      
                            <a class="btn btn-info" role="button" href="/Incident/OpenIncidentFromIncidentListJobDoneExpress/CfDJ8Hq-WaqbvO1LgvkM3H_V86HapN6hTNDlgi-2Z8ffa5bgqAgURJUWY3aM76R0hcDY1CmTypAU6WNPkl3mg8xBWbxLGbetw1huDzwr4PHyPsZjI6dkIT1Jv5bn5mdED12aTw?IncidentNo=CfDJ8Hq-WaqbvO1LgvkM3H_V86EWRhkKbUtHxTIKzC-K0LmFwf-fOqVqe5PTZdiWo0XMRNjrF_2fq0dD2AUODqRvADAPSU4AB68MRcMW6qFKPC7qOXNCTch-4R3TRq77CvThT3RRrkdhA3UqbWSH32BmTFs">Incident Solve</a>  
    

    How to insert redirect url and parameter into jQuery ?


  2. Jerry Lipan 916 Reputation points
    2022-01-18T09:21:47.497+00:00

    Hi @Zhi Lv - MSFT ,

    So far, I've this,

      var href = $(this).attr("href");  
                    window.location.href = href;  
    

    How to differentiate between href? We have 2 Link ( Yes, I'm response to this incident & Incident Resolve )

    Please help


  3. Jerry Lipan 916 Reputation points
    2022-01-19T07:47:55.257+00:00

    Hi @Zhi Lv - MSFT

    Your answer is great

    0 comments No comments