Copy text directly to clipboard in asp.net

I want the value I clicked on the event to be saved in the clipboard but this code does not work please see where my mistake is

<button class="btn btn-outline-warning" onclick="navigator.clipboard.writeText(@Model.projectCode)">@Model.projectCode</button>

Answer

You can use function below to copy element in clipboard

<button class="btn btn-outline-warning" onclick="copyToClipboard('@Model.projectCode')">@Model.projectCode</button>

function copyToClipboard(element) {
     var $temp = $("<input>");
     $("body").append($temp);
     $temp.val(element).select();
     document.execCommand("copy");
     $temp.remove();
}