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 4049000
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:53:20+00:00 2026-05-20T13:53:20+00:00

I am very new to MVC 3. I am using custom helpers for the

  • 0

I am very new to MVC 3.

I am using custom helpers for the controls but when i submit the form, the control is not being validated.

Can some one tell me if i am missing something? Following is the code snippet.

public static MvcHtmlString TextBox(string fieldName)  
{  
        TagBuilder tagBuilder = new TagBuilder("Input");

        tagBuilder.MergeAttribute("type", "Text");  
        tagBuilder.AddCssClass("text-box");  
        tagbuilder.MergeAttribute("data-val","true");
        tagbuilder.MergeAttribute("data-val-regex-pattern","true");  
        tagbuilder.MergeAttribute("data-val","true");

        TagBuilder validator = new TagBuilder("span");

        validator.MergeAttribute("data-valmsg-for", fieldName);  
        validator.MergeAttribute("data-valmsg-replace", "true");  
        validator.MergeAttribute("class", "field-validation-valid");  

        return new MvcHtmlString(string.Concat(tagBuilder.ToString(), validator.ToString()));  
}  

The view has the following code

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <div class="main-border" style="width: 890px;">
        <div style="clear: both;">
            &nbsp;
        </div>
        <div style="padding: 0px 20px 0px 20px;">
            <table style="width: 100%">
                <tr>
                    <td colspan="2" class="main-subhead2">
                        <div class="label-text">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>Email :</td>
                    <td>@ControlHelper.TextBox("txtEmailAddress")</td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" value="submit"  onclick="return validate(this.form);" /></td>
                </tr>
            </table>
        </div>
    </div>
}

the source code of rendered by the page is :

<form action="/" method="post">
    <div class="main-border" style="width: 890px;">
        <div style="clear: both;">
            &nbsp;
        </div>
        <div style="padding: 0px 20px 0px 20px;">
            <table style="width: 100%">
                <tr>
                    <td colspan="2" class="main-subhead2">
                        <div class="label-text">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>Email :</td>
                    <td><Input class="text-box" data-val="True" data-val-regex-pattern="^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z]))*@[A-Za-z0-9_\.-]+[A-Za-z0-9_][A-Za-z0-9_]$" name="txtEmailAddress" type="Text" visible="True"></Input><span class="field-validation-valid" data-valmsg-for="txtEmailAddress" data-valmsg-replace="true"></span></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" value="submit"  /></td>
                </tr>
            </table>
        </div>
    </div>
</form>
  • 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-05-20T13:53:21+00:00Added an answer on May 20, 2026 at 1:53 pm

    Input should be lowercased:

    TagBuilder tagBuilder = new TagBuilder("input");
    

    And don’t forget to include the unobtrusive client side validation scripts to your page:

    <script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
    

    and ensure that client side validation is enabled in web.config:

    <appSettings>
        <add key="ClientValidationEnabled" value="true"/> 
        <add key="UnobtrusiveJavaScriptEnabled" value="true"/> 
    </appSettings>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new with MVC, so bear with me, but I can't seem to
I'm very new to MVC, and just building my first site, using NerdDinner as
I am still very new to the MVC framework, but I managed to create
I am very new to ASP.NET and I am using the MVC 3 framework
I am very new to MVC. I've been learning to use plain HTML or
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
I'm very new to ASP.NET MVC, so forgive me if this is something I
I am relatively new to ASP.NET MVC, and am very impressed with the clarity
Very new to python and can't understand why this isn't working. I have a
Very new to C++ and Cocos2d-x but I was just toying around with CCArray

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.