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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:49:44+00:00 2026-06-17T01:49:44+00:00

I have the following model: public class PersonListModel { …. [Required(ErrorMessage=AppConstants.MustSelectRecordToAttachMessage)] public String SelectedPersonId

  • 0

I have the following model:

public class PersonListModel
{
   ....

    [Required(ErrorMessage=AppConstants.MustSelectRecordToAttachMessage)]
    public String SelectedPersonId { get; set; }
}

and the following view:

@using (Html.BeginForm("Attach", "Person", FormMethod.Post, new { @id = attachRecordFormId, targetDivId = personListId, @class = "inlineForm" }))
{
    .....

    @Html.HiddenFor(x => x.SelectedPersonId);

    .....

   <br />@Html.ValidationMessageFor(x => x.SelectedPersonId)
}

The hidden SelectedPersonId field is populated via some javascript hooked to the keyup event of one of the elements on my page.

My problem is that the required validation message shows immediately this partial view is displayed, not just when the form is submitted. It also displays again after the partial view is rendered again via an Ajax post.

I have very similar views that do not exhibit this problem, but 2 views (including the one above) that do exhibit this problem. I have been through a process of elimination to try to work out what is different between the views that work correctly and the 2 that exhibit this incorrect behavior, however I have not been able to locate the cause of the problem.

I presume that something is causing the unobtrusive validation to fire when the problem views are loaded. How can I track this down?

  • 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-17T01:49:45+00:00Added an answer on June 17, 2026 at 1:49 am

    My problem is that the required validation message shows immediately this partial view is displayed

    This could happen if the controller action that is displaying the view (containing the partial) takes the view model as argument:

    public ActionResult Display(MyViewModel model)
    {
        ... if this action is called with a GET request and you have missed
            to pass a value for the "SelectedPersonId" query string parameter 
            you will get a validation error in the corresponding view
    
        return View(model);
    }
    

    The reason for this happening is because your action is taking a model => the default model binder is kicking in attempting to populate your view model and when it attempts to set a value for the SelectedPersonId property it will automatically add a validation error to the model state if there’s no corresponding value in the request because your model property is decorated with the [Required] attribute.

    It also displays again after the partial view is rendered again via an Ajax post.

    That’s normal and could happen if the target POST action is taking your view model as argument and rendering a partial:

    [HttpPost]
    public ActionResult Process(MyViewModel model)
    {
        ... if this action is called with a POST request and you have missed
            to pass a value for the "SelectedPersonId" form parameter 
            you will get a validation error in the corresponding partial view
    
        return PartialView(model);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Model: public class Person { public string Name {get;set;} public
I have the following model: public class Person { public int ID{get;set;} public string
I have following model: public class FormularModel { [Required] public string Position { get;
I have the following Model: public class DeliveryTracking { public string TrackingRef { get;
I have the following model: public class A { public int? Id {get;set;} public
I have the following data model public class User { [Required(ErrorMessage = First name
ok say i have the following model: public class bar{ public string bar {get;
I have the following model: public class Person { public string Name { get;
I have the following model: public class Address { public int Id {get; set;}
I have the following model public class UserViewModel { public String CVR_Nummer { get;

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.