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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:34:56+00:00 2026-06-10T05:34:56+00:00

I have a @Html.TextBoxFor control with @Html.ValidationMessageFor, which is not a Required Field, but

  • 0

I have a @Html.TextBoxFor control with @Html.ValidationMessageFor, which is not a Required Field, but there is a limit in Maximum Length and also only numbers should be permitted. I have given the following code in the ViewModel :

    [StringLength(10, ErrorMessage = "The field Phone must have a maximum length of 10")]
    public string Phone { get; set; }

On the button click, I am unable to retrieve the above validation message while I had entered more than 10 characters.

And also How will I validate whether numeric ?

  • 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-10T05:34:57+00:00Added an answer on June 10, 2026 at 5:34 am

    The controller action that you are posting to must take the view model containing the Phone property as parameter:

    [HttpPost]
    public ActionResult SomeAction(MyViewModel model)
    {
        ...
    }
    

    or if this is not the case you should call the UpdateModel or TryUpdateModel methods inside to invoke the default model binder which is responsible for calling the validation logic and inserting any potential error messages into the ModelState.

    And also How will I validate whether numeric ?

    You could use a Regex:

    [StringLength(10, ErrorMessage = "The field Phone must have a maximum length of 10")]
    [RegularExpression(@"\d*", ErrorMessage = "The field Phone must contain only digits")]
    public string Phone { get; set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following field : @Html.TextBoxFor(model => model.Patient.dateOfBirth, new { id = datepicker,
My Datetime picker is working fine for Html.TextBoxFor but when i have Html.EditorFor it
I have a form with <td class=label>@Html.LabelFor(u => u.Link)</td> <td> @Html.TextBoxFor(u => u.Link) @Html.ValidationMessageFor(u
I have created a special User Control which inherits KeyValuePair. Inside my ViewModel, there
I have a Html.TextBoxFor which I would like to assign some dynamic javascript to
I have a @Html.TextboxFor and its connected to datepicker class, it also displays a
I have the following tag with a Html.TextBoxFor expression and I want the contents
I have a <%= Html.TextBoxFor(user => user.Name) %> and it has standart width. What
I have an ASPNET MVC 2 project. When I use <%= Html.TextBoxFor(model => model.Login)
So let's say I have a view that access a date: <%= Html.TextBoxFor(model =>

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.