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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:46:59+00:00 2026-06-05T11:46:59+00:00

i have an action and want to do some simple check on param ActionResult

  • 0

i have an action and want to do some simple check on param

ActionResult Test([Range(0,10)] int i)
{
  // ModelState.IsValid is always true, i want it to be false if i > 10 or i < 0
}

anyway to fix this or work around it or any alternatives provided by MVC?

  • 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-05T11:47:00+00:00Added an answer on June 5, 2026 at 11:47 am

    I thought of just checking the data annotation attribute definition before giving you some alternate options. I surprised to see that the AttributeUsage is defined in such that you can apply to the method parameters as well and unfortunately it not worked as i tried myself. Though I’m not sure why they have allowed this parameter to method parameters (I see it’s valid but not working)

    Regarding alternate options you could try this,

    public ActionResult Test(int i)
    {
       var rangeAttr = new RangeAttribute(0, 10);
    
       if(!rangeAttr.IsValid(i))
         ModelState.AddModelError(i.ToString(), rangeAttr.FormatErrorMessage("i"));       
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have link for example domain.com/de/controler/action?param=value and I want make actionlink to keep same
I have an action which create QMessageBox. In that dialog I want to print
I have two action methods that are conflicting. Basically, I want to be able
I have controller with action new , and I want it to create ActiveRecord::Base
I have a stripes action page. and When the page loads, I want to
I want to have possibility to access action by the following URL type: http://localhost/MyControllerName/MyActionName/Id1+Id2+Id3+Id4
I have code that I want to be executed before every action is called.
I want to have a route that looks something like: www.abc.com/companyName/Controller/Action/Id However, all the
I have a form whose action is set to itself. I want it this
I have an IBAction with some simple code inside: -(IBAction)change:(id)sender { [textfield setHidden:NO]; [self

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.