Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8643811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:08:36+00:00 2026-06-12T12:08:36+00:00

I have a contact page in mvc . I have a 4 text box

  • 0

I have a contact page in mvc . I have a 4 text box in this page and
one text area and i want to give validation using jquery the
text-box id is txtbxName, txtbxCompany, txtbxEmail, txtbxPhone ,and
txtarMessage. when user click on submit button if txtbxName is blank.
i want a message something like this “Please enter your Name!” and so
on. please help me thanks

ContactController.cs 

         public ViewResult Create(string Name, string Company, string Regarding, string Email, string Phone, string Message)
         {
            string body = "Name: " + Name + "<br>" + "\nCompany: " + Company + "<br>" + "Regarding: " + Regarding + "<br>" + "Email: " +
 Email + "<br>" + "Phone: " + Phone + "<br>" + "Message: " + Message;
           try
           {                 MailMessage mail = new MailMessage();                 mail.From = new MailAddress("g@technosys.com");
                mail.To.Add("p@technosys.com");
                 mail.Subject = "Accept Request";
                 mail.Body = body;
                mail.IsBodyHtml = true;               SmtpClient smtp = new SmtpClient("smtp.gmail.com");
                smtp.Credentials = new System.Net.NetworkCredential("g@technosys.com", "1457898");
                smtp.EnableSsl = true;
                 // smtp.UseDefaultCredentials = true;
                 smtp.Send(mail);
             }
             catch (Exception ex)
             {
                 ViewData.ModelState.AddModelError("_FORM", ex.ToString());
             }
             return View();



 Jquery


 $("#btnSubmit").click(function (event) {




         var data = { Name: $("#txtbxName").val(), Company: $("#txtbxCompany").val(), Regarding:
             $("#ddlRegarding").val(), Email: $("#txtbxEmail").val(), Phone: $("#txtbxPhone").val(), Message:
             $("#txtarMessage").val()
         }




           $.ajax({
             type: "POST",
             url: "/Contact/Create",  // the method we are calling
             contentType: "application/json; charset=utf-8",
             data: JSON.stringify(data),

             dataType: "html",
             success: function (result) {
                 $("#txtbxName").val("");
                 $("#txtbxCompany").val("");
                 $("#txtbxEmail").val("");
                 $("#txtbxPhone").val("");
                 $("#txtarMessage").val("");
                 alert(result);
                 // Or if you are returning something
                 alert('I returned... ' + result.WhateverIsReturning);
             },
             error: function (result) {
                 $("#txtbxName").val("");
                 $("#txtbxCompany").val("");
                $("#txtbxEmail").val("");
                 $("#txtbxPhone").val("");
                 $("#txtarMessage").val("");

                 alert('Thanks for sending info');
                 return false;
             }
         });
     });



 Index  .cshtml


 <div class="parteners">
                 <div class="block" style="width: 270px;">
                     <div class="block" style="width: 295px; padding: 3px;">
                         Name :
                     </div>
                     <div class="block" style="width: 320px; padding: 3px;">
                         <input type="text" class="textbox" name="textfield" alt="Type our Name here" />>                         <br />
                   </div>
                     <div class="block" style="width: 295px; padding: 3px;">
                         Company :
                     </div>
                     <div class="block" style="width: 295px; padding: 3px;">
                        <input type="text" class="textbox" name="textfield2" />
                    </div>
                     <div class="block" style="width: 295px; padding: 3px;">
                         Regarding :
                     </div>
                     <div class="block" style="width: 295px; padding: 3px;">
                         <select name="select" class="textbox">
                             <option>General Inquiry</option>
                             <option>Programming Related Question</option>
                             <option>Website Quote Request</option>
                             <option>Feedback</option>
                             <option>Help and Support</option>
                         </select>
                     </div>
                 </div>
                 <div class="block" style="width: 270px;">
                     <div class="block" style="width: 295px; padding: 3px;">
                         Email :</div>
                     <div class="block" style="width: 295px; padding: 3px;">
                        <input type="text" class="textbox" name="textfield3" />
                     </div>
                     <div class="block" style="width: 295px; padding: 3px;">
                         Phone :
                     </div>
                     <div class="block" style="width: 295px; padding: 3px;">
                         <input type="text" class="textbox" name="textfield4" />
                     </div>
                 </div>
                 <div class="block" style="width: 600px; padding: 3px;">
                     Enter your Suggestions / Comments / Feedback here :
                 </div>
                 <br />
                 <div class="block" style="width: 600px; padding: 3px;">
                     <textarea class="textarea" name="textarea"></textarea><br />
                     <br />
                 </div>
                 <div class="block" style="width: 600px; padding: 3px;">
                     <input id="Button1" type="Button" value="Submit" />
                 </div>
             </div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:08:37+00:00Added an answer on June 12, 2026 at 12:08 pm

    Set class to all the textboxes like below

    <input type="text" class="valcheck" title="Name" id="your_name_field_id" name="your_name_field_name" />

    do the same for all the 6 textboxes.

    $("#btnSubmit").click(function (event) { 
    
     $(".valcheck").each(function(){
    
      var id = this.id;
      var field_value = $("#"+id).val();
    
      if(field_value=="")
      {
       var field_name = $("#"+id).attr('title');
       $("#error_display_div").append("Please enter "+field_name+"<br />");
      }
    
    //Show hide error_display_div accordingly, you can clear out the div using
    // $("#error_display_div").html('');
    
     });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm confused about MVC routes. Let's say I have this domain: poopoopants.com. I want
I have a contact us page in my website using ASP.NET http://sosdeepcleaning.com/contactus.aspx When clients
I have a contact page (contact.php) that sends a form (formsend.php) when people fill
I have a website and contact page in it. Anybody can go in there
I'm writing a contact page, but I have a strange problem. Right from the
In my .aspx page which derives from a master page I have a contact
I have page, i can contact directly without any problems. http://www.mysite.com/app_dev.php/comments/22 the page shows
I have a user profile page on my web app which has contact information.
I have the typical HTML "contact me" page, i.e. name, e-mail address and message.
This is what I want: Let's say I have a textbox and a button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.