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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:07:17+00:00 2026-05-25T06:07:17+00:00

I have a model which has 2 fields, a and b like this: class

  • 0

I have a model which has 2 fields, “a” and “b” like this:

class AbModel
{
    public string a {get;set;}

    [SomeValidation]
    public int b {get;set;}
}

Now “b” is actually hidden in the gui, and “a” shows a textual representation of it.

<div class="editor-field">
    <%= Html.HiddenFor(model => model.b, new { id = "ABModelEditor_b" })%>
    <%= Html.TextBoxFor(model => model.a, new { id = "ABModelEditor_a" })%>
    <input type="button" value="Change" onclick="AbModelEditorScript.showAbSelector(); return false;" />
</div>

Generates the following on “save” with empty data:

<div class="editor-field">
    <input class="input-validation-error" id="ABModelEditor_b" name="b" type="hidden" value="">
    <input id="ABModelEditor_a" name="a" type="text" value="">
    <input type="button" value="Change" onclick="AbModelEditorScript.showAbSelector(); return false;" />
</div>

I need the the input-validation-error css class to be attached to the “a” textbox instead of the hidden for “b”.

Before I simply move the css-class with a jquery-script, is there some other way that I should consider, perhaps some built in functionality?

  • 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-05-25T06:07:18+00:00Added an answer on May 25, 2026 at 6:07 am

    Are you using unobtrusive validation? The other option is to add the validation attributes with jQuery and revalidate the form…

    $("#ABModelEditor_a").attr("data-val-required", "true"); //add your validation attributes to the input tag
    
    var form = $("form");
    form.removeData("validator").removeData("unobtrusiveValidation") // this will clear the validation from the form
    $.validator.unobtrusive.parse(form); //reattach the validation
    

    This will give you real client side validation, but it still won’t match your model. You’ll have to fill in the gap on the server side.

    In regards to your comment about server-side only validation.

    You can try to manually add the model error to the model state. This should be reflected in your view when you return.

    ModelState.AddModelError(string key, string errorMessage);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model class like following public class ProductModel { string ProductName {
I have an ActiveRecord model, Foo , which has a name field. I'd like
I have a model called Contact which has_one guest like so. class Contact <
In my domain model I have an abstract class CommunicationChannelSpecification, which has child classes
What I have is a model which has one of it's attributes dynamic. This
I have an Address Model which has a ForeignKey to a Contact Model: class
I have a Project model. This model has Days which are inlines . How
I have a model class 'Market' which has many products: class Market < ActiveRecord::Base
I have a model called Metadatum (silly, I know) which has two fields, key
I have a django model which has a load of relatively small fields and

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.