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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:15:01+00:00 2026-05-23T07:15:01+00:00

I have written some extension methods that extend the html helper class for client

  • 0

I have written some extension methods that extend the html helper class for client side form validation. What I’d like to be able to do is have the page loaded with an array (javascript) of all of my elements that are part of my validation “library”.

example:

@Html.VTextBox("blah)
@Html.VDropDownList("bling")
@Html.VTextBox("bloo")

when the page is loaded, I’d like a javascript array placed at the top filled with something like this:

errorListArr = new Array("blah","bling","bloo");

Currently what I’m doing is using errorListArr.push() for each element and writing out script tags each time … clearly not the most elegant way to do this. I’d also like to figure out how I can parse the whole page ahead of time so that I can put together my list of elements that I’m going to need to validate server side.

Please let me know if this can be done and any code snippet/samples would be appreciated.

  • 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-23T07:15:01+00:00Added an answer on May 23, 2026 at 7:15 am

    I’m not entirely clear on what you’re trying to do, but I think I understand enough to point you in the right direction.

    First of all, server-side validation in MVC 3 is typically done as a postback to an action that takes a model and validates it. If the model isn’t valid, you return the view with the (now-validated) model, and the view will render the appropriate error messages for the properties that were wrong.

    By default, you can define what validation to perform by adding certain attributes to the properties on the model that you’re rendering inputs for.

    What’s more, MVC is smart enough to output client-side javascript to perform many of these validations when the user tries to submit the form, without actually requiring a post-back at all!

    See this post for a walk-through of how to use model validation.

    In MVC 3, you also have the option to enable “unobtrusive javascript” validation, which basically does the same client-side validation as usual, but instead of generating a bunch of inline javascript, it simply flags the input elements with certain “data-” attributes. A couple of jquery-based libraries then scan the page for elements with these flags, and add the appropriate validation handlers to them.

    If you have validation needs that go beyond what MVC offers out of the box, it is easy to add your own validation attributes, or even make your model perform custom logic to validate itself.

    Generally speaking, if you find that you’re rendering a lot of little javascript snippets client-side, you may want to follow the “unobtrusive javascript” pattern yourself:

    1. Put code in a static javascript file that knows how to scan the DOM for specific flags that it’s interested in.
    2. Render your HTML elements with these flags added, using “data-” attributes to add specifics where necessary.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class library with some extension methods written in C# and an
I have written some extension methods for UrlHelper in order to more easily load
I have written an extension method in csharp for an MVCContrib Html helper and
I have a file (with extension.hgx) that has some data like this: length =
I have written a Chrome extension that adds a char counter to some input
I am writing some unit tests for an extension method I have written on
I have written some extension modules for eJabberd most of which pass pieces of
I have written some code that loads an XML document using an XmlDocument object
I have written a custom dialog (form) that I can use in a C#
I have written some C/C++ extension modules for PHP, using the 'old fashioned way'

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.