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

  • Home
  • SEARCH
  • 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 996255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:50:54+00:00 2026-05-16T06:50:54+00:00

This question title is likely to be worded poorly so feel free to adjust.

  • 0

This question title is likely to be worded poorly so feel free to adjust.

In my MVC application I have a custom attribute which i use to decorate email fields which then either passes or fails the model.

On one pge though I allow the use to submit a comment but I submit via ajax and so do not do a full postback and no model validation.

So I’d like to validate the address but not copy the code. I’d also like to avoid breaking the code out of the validator into yet another class or is this the best wAY?

Is there another way? Can I create the model in the ajax postback and validate it there and then return the partial view with the error messages?

Or is there another way?

  • 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-16T06:50:55+00:00Added an answer on May 16, 2026 at 6:50 am

    You say, …

    So I’d like to validate the address but not copy the code. I’d also like to avoid breaking the code out of the validator into yet another class or is this the best way?

    IMO, that is the best way. Factor out the common code. I see your issue though, our EmailValidator inherits from RegularExpressionValidator, so it’s hard to factor out. We have a RegEx utility class that uses the same RegEx pattern. We refer to the pattern by constant in both places…

    public class EmailAttribute : RegularExpressionAttribute
    {
      public EmailAttribute() :
        base(RegExUtility.SingleEmailAddressPattern)
      {
        ErrorMessage = "Please enter a valid email address";
      } 
    

    and

    public static class RegExUtility
    {
      public const SingleEmailAddressPattern = @"...";
    
      public static bool IsValidSingleEmailAddress(string email)
      {
         return Regex.IsMatch(email, SingleEmailAddressPattern);
    

    For simple Ajax postback actions, I think you can often handle it in the controller or create a separate POCO ViewModel that just supports the Ajax path. I know there are articles on using the same model for both types of actions, but we’ve found there are usually enough differences that it’s worth having separate view models. If they’re complex enough, we just factor out the common code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Really strugging to title this question, so if anyone has suggestions feel free.) Say
I'm sorry, I have no idea how to title this question. I've written an
I have no good title for this question, but my problem is to set
I have customer that uses older, custom built ERP application for which they don't
I realize this question is very likely to have been asked before, but I've
I am making an email application which is giving the error in this question's
This question is a bit of a two-parter. First, the title question. Here's what
I wasn't sure what to title this question. Here's my goal: On page one,
i didn't really know how to title this question, but here's a thing that
This question Add a version number to the title of a LaTeX document spurred

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.