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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:55:13+00:00 2026-06-02T04:55:13+00:00

I am having a very weird problem I have a viewModel: public class ServiceView

  • 0

I am having a very weird problem

I have a viewModel:

public class ServiceView
{
    [Required]
    [Display(Name = "Titre de l' annonce")]
    public string NomService { get; set; }

    [Required]
    [Display(Name = "Description")]
    public string DescriptionService { get; set; }

    [Display(Name = "Adresse")]
    public string AdresseService { get; set; }

    [Display(Name = "Le code postal")]
    public int CodePostalService { get; set; }

}

and a View which is tight to my ViewModel:

@model MeilleurPresta.Models.ViewModel.ServiceView

@{
    ViewBag.Title = "Déposer une offre";
}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>


<div class="grid_23" id="body">

    <h3 style="padding-left: 50px"> Déposer une offre de Service </h3>

    <div style="margin-left: 50px">
        @using (Html.BeginForm()) {

            @Html.ValidationSummary(true)

            <div class="editor-label">
                @Html.LabelFor(model => model.NomService)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.NomService)
                @Html.ValidationMessageFor(model => model.NomService)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.DescriptionService)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.DescriptionService)
                @Html.ValidationMessageFor(model => model.DescriptionService)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.AdresseService)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.AdresseService)
                @Html.ValidationMessageFor(model => model.AdresseService)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.CodePostalService)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.CodePostalService)
                @Html.ValidationMessageFor(model => model.CodePostalService)
            </div>

            <p>
                <input type="submit" value="Create" />
            </p>
        }
    </div>
</div>

My controller:

    public ActionResult Index()
    {
        return View();
    }

Nothing special, however, when I submit the form, on client validation, it indicates me that the field: Le code postal is required, but it is not in the ViewModel.

I inspect the html source code, it generates the data-val-required class whereas in my ViewModel there are no require attributs.

Where the problems may come from ?

thanks

  • 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-02T04:55:15+00:00Added an answer on June 2, 2026 at 4:55 am

    Because your int isn’t nullable, it’s marked required by default. You can either set the int to int? to make it nullable or you can add this to your application_start to change the default behavior…

    DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a very weird CSRF protection problem in CodeIgniter. I have made
Im having a very strange problem, i have a complicated view that returns incorrect
I'm having a very weird problem with a vector in my application. Details... I
I am having a very weird problem that I've never had before when using
i having a very weird problem now . I has separate 2 jquery js
I'm having a very weird issue here, I have set-up my solr architecture as
I'm having a very weird problem with radio buttons in JQuery Mobile. I'm populating
I'm having a very weird problem.I'm working on an assignment that involves building a
I'm working with jQuery's .get() function and I'm having a very weird problem using
I'm having a very weird problem that for the life of me I can

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.