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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:49:36+00:00 2026-05-20T23:49:36+00:00

My model is something like this: public class Line { public int CatalogNumber {get;

  • 0

My model is something like this:

public class Line
{
    public int CatalogNumber {get; set;}
    public int TeamCode {get; set;}
}

I have a view that gets catalog number and a team code, And I want to check two things:

  1. there is such catalog number in our database
  2. There is such catalog number for the given team

I wrote an attribute (that derives from ValidationAttribute) that checks if there is such a catalog number in our Data Base. But it does nothing!

Maybe it’s impossible to such check with an attribute?

(I know that I can implement IValidable and override IsValid method but for my own reasons I prefer doing it with an attribue).

I’ve to do it without serverPost (ajax would be good)

I’ll really appreciate a good example hot to do it.

p.s. (We are using mvc3)

  • 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-20T23:49:37+00:00Added an answer on May 20, 2026 at 11:49 pm

    I think that Remote Validation could help you out with this problem. You could use it to check that the catalog number exists in the database:

    public class Line
    {
        [Remote("QueryCatalogNumberExists", "Home")]
        public int CatalogNumber { get; set; }
        public int TeamCode { get; set; }
    }
    

    Then in your controller (I haven’t tested this code but it should be something along the lines of):

    public JsonResult QueryCatalogNumberExists(int catalogNumber)
    {
        if (_repository.QueryCatalogNumberExists(catalogNumber))
        {
            return Json(true, JsonRequestBehavior.AllowGet);
        }
        return Json(false, JsonRequestBehavior.AllowGet); 
    }
    

    I believe you can also have additional fields so that you could check that the catalog number is valid for the given TeamCode (I think the TeamCode would have to be nullable as the user may not enter one before entering a catalog number in your current model as the team code is not required). So your model would be:

    public class Line
    {
        [Remote("QueryCatalogNumberExistsForTeamCode", "Home", AdditionalFields = "TeamCode")]
        public int CatalogNumber { get; set; }
        public int TeamCode { get; set; }
    }
    

    and the controller code:

    public JsonResult QueryCatalogNumberExistsForTeamCode(int catalogNumber, int? teamCode)
    {
        if (_repository.QueryCatalogNumberExistsForTeamCode(catalogNumber, teamCode))
        {
            return Json(true, JsonRequestBehavior.AllowGet);
        }
        return Json(false, JsonRequestBehavior.AllowGet); 
    }
    

    I hope this points you in the right direction to a solution.

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

Sidebar

Related Questions

I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
If i have a ViewModel like this: public class MyViewModel { [UIHint(SomeTemplate)] public ICollection<SomeViewModel>
Generally, MVC frameeworks have a structure that looks something like: /models /views /controllers /utils
I want to bind a treeview to a class like this one: public class
Is there something like python's interactive REPL mode, but for Java? So that I
So no doubt that building a domain model is something that I think happens
Domain Model I am working on has root aggregate and child entities. Something like
I want to implement something like this using JSF.(part of search screen) More and
I have a Datagrid that gets its data from an ArrayCollection of model beans.
In Model-View-Presenter pattern where should we write validations of user input.

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.