Click here to Skip to main content
15,889,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Goal:
*When you press the submit button a client validation should be executed inside of a textbox.

*If okey, go the the actionresult.
Otherwise, show a popup message with statement "max 10 letter" with a OK button.

The criteria is that max 10 letters.

Problem:
I don't know how to do it in relation to ASP.net MVC's sourcecode.

Info:
*I'm using VS2013 with ASP.net mvc, jQuery, javascript
*No server validation!!!
*It would be great that the code can be working for many web browser.



View

C#
@using (Html.BeginForm("Create", "Test", FormMethod.Post)
{
<input type="text" value="" />

<input type="submit" value="Search" />

@Html.AntiForgeryToken()
}
Posted
Comments
F-ES Sitecore 26-May-15 9:44am    
google "asp.net mvc client-side validation"

Also no server-side validation is s recipe for disaster. Client-side validation is a nice to have, but server-side validation is a must. Remember the client can disable client-side validation so you need server validation there as a back-up. The built-in validation framework handles all of this for you.

check this...
JavaScript
$("#button").click(function() {
  if($.trim($("#textbox").val()).length>10)
  {
    alert('The criteria is that max 10 letters. ');
    return;
  }
});


change the id of button and textbox according to your project.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900