Friday, 8 April 2016

Validation Of Form To Display Error Message as ToolTip Using jQuery In Asp.Net MVC

4/08/2016 - By Pranav Singh 0

This article will show you how you can create a custom validation of form using jQuery in your asp.net mvc application. In this we will display the error message as a tooltip.
So for this article first we will create a new asp.net application and add a model class file and add the below code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Vaidation.Models
{
    public class UserModel
    {
        public string name { get; set; }
        public string emailid { get; set; }
        public string password { get; set; }
        public string phoneno { get; set; }
    }
}

Now add a below controller class file and add the below code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vaidation.Models;

namespace Vaidation.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        [HttpGet]
        public ActionResult Index()
        {
            UserModel userModel = new UserModel();
            return View(userModel);
        }
        [HttpPost]
        public ActionResult Index(UserModel userModel)
        {
            ViewBag.Message = "Data Recived successfully.";
            return View(userModel);
        }

    }
}

In above code I have added get and set method. In this post method will receive the entered data. After receiving data we will pass success message.
Now create the view file and add the below code.
@model Vaidation.Models.UserModel
@{
    ViewBag.Title = "Validation Of Form To Display Error Message as ToolTip Using jQuery In Asp.Net MVC";
  
 <link rel="stylesheet" href="../../css/validationEngine.jquery.css" type="text/css" />

    <script src="../../js/jquery-1.8.2.min.js" type="text/javascript">
       </script>

    <script src="../../js/languages/jquery.validationEngine-en.js" type="text/javascript"
        charset="utf-8">
       </script>

    <script src="../../js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
    <script>
        jQuery(document).ready(function () {
            jQuery("#frmRegistration").validationEngine({
                notEmpty: true
            })
        });
       </script>
}
<form id="frmRegistration" class="formular" method="post" action="">
<table width="100%" cellpadding="5" cellspacing="10">
    <tr>
        <td colspan="2" align="center">
            <h2>
                Registration Form</h2>
        </td>
    </tr>

    <tr>
        <td align="right">
            User Id :
        </td>
        <td align="left">@Html.TextBoxFor(m => m.name, new { @class = "validate[required] text-input" })
        </td>
    </tr>
    <tr>
        <td align="right">
            Email :
        </td>
        <td align="left">@Html.TextBoxFor(m => m.emailid, new { @class = "validate[required,custom[email]] text-input" })
        </td>
    </tr>
    <tr>
        <td align="right">
            Password :
        </td>
        <td align="left">@Html.PasswordFor(m => m.password, new { @class = "validate[required] text-input" })
        </td>
    </tr>
    <tr>
        <td align="right">
            Phone No:
        </td>
        <td align="left">@Html.TextBoxFor(m => m.phoneno, new { @class = "validate[custom[phone]] text-input" })
        </td>
    </tr>
        <tr>
        <td colspan="2" align="center" style="color:Green;font-weight:bold;">
           @ViewBag.Message
        </td>
    </tr>
    <tr>
        <td align="center" colspan="2">
            <input type="submit" value="Submit" />
        </td>
    </tr>
</table>
</form>

In above code I have added the library reference and the jquery function. Now we have done . Run the application to check the output.



About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top