SHOW MESSAGE WHEN USER EXCEED LIMIT SIZE OF A TEXTBOX IN ASP.NET MVC APP

Manish Sahu

Total Post:47

Points:331
Posted by  Manish Sahu
Mvc4 
C#
 455  View(s)
Ratings:
Rate this:

Show message when user exceed limit size of a textbox in asp.net mvc app

I am developing a mvc application in that I want to display a message when the user types more than 20 characters in the textbox. This needs to validate without clicking on any validate button.

This is my current code :

<span class="field">@Html.TextBoxFor(d => d.Name,new {maxlength=20})</span>
  1. Sunil Singh

    Post:45

    Points:323
    Re: Show message when user exceed limit size of a textbox in asp.net mvc app

    Use this code

    In the Model

    [StringLength(250, ErrorMessage = "Description must not be more than 250 chars")]
    
            public string Name{ get; set; }
    View code
    HtmlHelper.ClientValidationEnabled = true;
    
      HtmlHelper.UnobtrusiveJavaScriptEnabled = true;

    <div class="col-md-12">
                                    <div class="form-group">

                                        @Html.TextAreaFor(m => m.Name, new { @class = "form-control"})
                                        @Html.ValidationMessageFor(x=>x.Name)
                                    </div>
                                </div>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!