In this article I will explain with an example, how to set MaxLength for TextArea using jQuery in ASP.Net Core Razor Pages.
The ASPSnippets MaxLength jQuery plugin will be used to set the MaxLength in the TextArea element in ASP.Net Core Razor Pages.
Download ASPSnippets MaxLength Plugin
You can download the ASPSnippets MaxLength jQuery plugin using the link provided below.
Using ASPSnippets MaxLength jQuery Plugin
The ASPSnippets MaxLength jQuery has the following required and optional parameters:-
1. MaxLength (required) – Integer value indicating the Maximum character length limit.
2. CharacterCountControl (optional) – By default the plugin will display character count below the TextArea, but user has option to explicitly specify the Character Count Control.
Note: The character count control can only be a HTML SPAN or DIV element.
3. DisplayCharacterCount (optional) – Default true. If set to false the Character counting will be disabled.
Razor PageModel (Code-Behind)
The PageModel consists of following one Handler method.
Handler method for handling GET operation
This Handler method handles the GET calls, for this particular example it is not required and hence left empty.
public class IndexModel : PageModel
    public void OnGet()
Razor Page (HTML)
The HTML of Razor Page consists of three TextArea elements for which the Maximum Length validation will be implemented and an HTML DIV element for displaying the Character Count for the second TextArea.
Implementing ASPSnippets MaxLength jQuery Plugin
Inside the jQuery document ready event handler, the ASPSnippets MaxLength jQuery plugin has been applied to all the three TextArea elements with three different configurations.
First TextArea – Default configuration. Maximum Length validation will be performed and Character count will be displayed.
Second TextArea – Maximum Length validation will be performed and Character Count will be displayed in a HTML DIV.
Third TextArea – Only Maximum Length validation will be performed.
Note: JS file does not work in ASP.Net Core unless it is placed in proper location within the project and also some settings need to be done. For more details, please refer my article Static Files (Images, CSS and JS files) in ASP.Net Core.
    Layout = null;
<!DOCTYPE html>
    <meta name="viewport" content="width=device-width" />
    <style type="text/css">
        body { font-family: Arial; font-size: 10pt; }
        .error { color: red; font-weight: bold; }
    <textarea id="Text1" rows="2" cols="20"></textarea>
    <div id="counter" class="error"></div>
    <textarea id="Text2" rows="2" cols="20"></textarea>
    <textarea id="Text3" rows="2" cols="20"></textarea>
    <script type="text/javascript" src=""></script>
    <script src="~/Scripts/MaxLength.min.js"></script>
    <script type="text/javascript">
        $(function () {
            //Default Configuration.
            $("#Text1").MaxLength({ MaxLength: 10 });
            //Specifying the Character Count control explicitly.
                MaxLength: 15,
                CharacterCountControl: $('#counter')
            //Disable Character Count.
                MaxLength: 20,
                DisplayCharacterCount: false
ASP.Net Core Razor Pages: Set Maxlength for TextArea using jQuery
Browser Compatibility

The above code has been tested in the following browsers.

Internet Explorer  FireFox  Chrome  Safari  Opera 

* All browser logos displayed above are property of their respective owners.