In this article I will explain with an example, how to disable mouse right click using jQuery in ASP.Net Core (.Net Core 8) MVC.
Note: For more details on ASP.Net Core (.Net Core 8) MVC, please refer my article ASP.Net Core 8: Hello World Tutorial with Sample Program example.
 
 

Script to disable Right Click using jQuery

Inside the HTML Markup, following jQuery JS file is inherited.
1. jquery.min.js
 
Inside the contextmenu event handler, the event is cancelled by returning FALSE.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script type="text/javascript">
    //Disable the Context Menu event.
    $(document).contextmenu(function () {
        return false;
    });
</script>
 
 

Controller

The Controller consists of following Action method.

Action method for handling GET operation

Inside this Action method, simple the View is returned.
public class HomeController : Controller
{
    public IActionResult Index()
    {
        return View();
    }
}
 
 

Disabling Mouse Right Click using jQuery in View

You will need to place the following script in HEAD section of your View (.cshtml) or Layout page.
@page
@{
    Layout = null;
}
 
<!DOCTYPE html>
 
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <style type="text/css">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script type="text/javascript">
        //Disable the Context Menu event.
        $(document).contextmenu(function () {
            return false;
        });
    </script>
</head>
<body>
    <h1>Try to Right Click on this Page.</h1>
</body>
</html>
 
 

Screenshot

ASP.Net Core: Disable Mouse Right Click using jQuery
 
 

Demo

 
 

Downloads