ASP.NET MVC Validation

Posted by Community Admin on 04-Aug-2018 00:01

ASP.NET MVC Validation

All Replies

Posted by Community Admin on 26-May-2014 00:00

Hi all,

I have a quick question regarding MVC validation within MVC widgets.  I've noticed that on-submit validation works beautifully - the form gets sent, fails to validate and I can show any relevant messages for the user to correct.

I was wondering if there's any support for the inline validation that MVC would normally allow - where each field is validated on the fly rather than on submit?

 

Posted by Community Admin on 27-May-2014 00:00

Hello Nick,

Along with your server-side validation, you can add a client-side validation by using for example JavaScript, where to add a violation message and/or to hide/deactivate the submit button (example).

Below is the sample code used in the View:

<script>
    function test()
        var name = document.getElementById('name').value;
        console.log(name.length);
        if (name.length >= 3)
            document.getElementById('err1').setAttribute("style", "display: none");
        
        else
            document.getElementById('err1').setAttribute("style", "color:red; display: inline-block");
        
    
</script>
 
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
    First name:
    <input type="text" name="fname" onchange="test()" id="name">
    <span id="err1" style="display:none">Please enter at least 3 charecters</span>
    <br />
    <input type="submit" value="Submit">
</form>

You could check the proposed solution in that forum post also.

Regards,
Svetoslav Manchev
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed