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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:41:19+00:00 2026-06-09T07:41:19+00:00

I am using DataAnnotationsExtensions from http://dataannotationsextensions.org/ with an example from here http://weblogs.asp.net/srkirkland/archive/2011/02/23/introducing-data-annotations-extensions.aspx Controller Code

  • 0

I am using DataAnnotationsExtensions from http://dataannotationsextensions.org/

with an example from here http://weblogs.asp.net/srkirkland/archive/2011/02/23/introducing-data-annotations-extensions.aspx

Controller Code

    public ActionResult Create(Dog dog, HttpPostedFileBase Picture)
    {
        Regex rgx = new Regex(@"^.*\.(jpg|gif|jpeg|png)$");
        Match m = rgx.Match(Picture.FileName);

        if (rgx.IsMatch(Picture.FileName))
            {
                if (ModelState.IsValid)
                {

Model Code

[FileExtensions("png|jpg|jpeg|gif", ErrorMessage = "Only jpg jpeg gif or png files allowed")]
        public string Picture { get; set; }

and the razor code

@Html.TextBoxFor(model => model.Picture, new { type = "file" })
@Html.ValidationMessageFor(model => model.Picture)

Everything I do it fails everytime at

if (ModelState.IsValid)

If I remove the FileExtensions Annotation it works fine but then I no longer have the ability to block file types that I dont want.

I have gone as far as to check the code for the data annotations extentions located here
https://github.com/srkirkland/DataAnnotationsExtensions/blob/master/DataAnnotationsExtensions/FileExtensionsAttribute.cs

and I still cant seem to find out where the problem is.

  • 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-09T07:41:20+00:00Added an answer on June 9, 2026 at 7:41 am

    I believe that the model binder is getting confused with a property named ‘Picture’ on your model and a HttpPostedFileBase parameter named ‘Picture’ as well.

    If you update your HttpPostedFileBase parameter to something other than ‘Picture’, the model binder should behave normally. Example:

    public ActionResult Create(Dog dog, HttpPostedFileBase UploadedPicture)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
I'm using ASP.NET MVC3 and trying to validate an URL field using DataAnnotationsExtensions. It's
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using mercurial, I've run into an odd problem where a line from one committer
Using Android TelephonyManager an application can obtain the state of data activity over the
Using php/html, I want to retrieve email addresses (plus other information) from MySQL and
Using Core Data, I have a fetch request to fetch the minimum of a
(Using MVC 2) From inside my controller action, I need to display the url:

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.