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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:02:13+00:00 2026-06-12T00:02:13+00:00

I have a object like this: public class Test { public String TestValue {

  • 0

I have a object like this:

public class Test
{
    public String TestValue { get; set; }
}

For this object there is a custom editor for template:

@inherits System.Web.Mvc.WebViewPage<MvcApplication12.Models.TestModel>
@Html.EditorFor(m => m.TestValue)

and a Model-Binder:

public class TestBinder : IModelBinder
{
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        ValueProviderResult providerValue =
            bindingContext.ValueProvider.GetValue(bindingContext.ModelName + ".TestValue");
        bindingContext.ModelState.SetModelValue(bindingContext.ModelName + ".TestValue", providerValue);            

        if (null != providerValue && !String.IsNullOrWhiteSpace(providerValue.AttemptedValue))
        {
            Test test = new Test();
            test.TestValue = providerValue.AttemptedValue;
            return test;
        }

        return null;
    }
}

The Model for the Controller is like this:

public class LogOnModel
{
    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [Required]
    [Display(Name = "Value")]
    public Test Value { get; set; }
}

You can see, I use the Test object, that will be rendered by the custom editor for template shown above.

the razor syntax is like that:

            <div class="editor-label">
            @Html.LabelFor(m => m.Password)
        </div>
        <div class="editor-field">
            @Html.PasswordFor(m => m.Password)
            @Html.ValidationMessageFor(m => m.Password)
        </div>

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

The data anotiation in the model says, that the input for the test object (m.Value) is required. When there is no input for this field, the ModelBinder (TestBinder) will return null.

Then the validation message is displayed like this:

Web Page

But the css class called “input-validation-error” is not added to the input field.

How can I achieve, that on an Model-Error mvc3 adds the css class “input-validation-error” to all nested input fields of an custom editor template?

  • 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-12T00:02:14+00:00Added an answer on June 12, 2026 at 12:02 am

    finally I solved it.
    There are two ways to do it.

    1. If there is only one Field in your custom editor for, you can use a textbox where you do not set the name

    @inherits System.Web.Mvc.WebViewPage<MvcApplication12.Models.TestModel>
    @Html.TextBox("", Model.TestValue)

    1. But maybe you have more than one fields in your custom editor for.

    First you have to change your css file and add one line like this

    .inner-input-validation-error input[type=text]

    here you can now say how your error fields will look like. Maybe like this

    .inner-input-validation-error input[type=text],
    input.input-validation-error,
    textarea.input-validation-error,
    select.input-validation-error
    {
        border: 1px solid black;
        background-color: red;
        font-size:100%;
    }
    

    Now change your custom editor for template, so that you add the class .inner-input-validation-error on error in a span, containing your edit fields

        @inherits System.Web.Mvc.WebViewPage<MvcApplication12.Models.TestModel>
        <span
            @if (!ViewData.ModelState.IsValid)
            {
                <text>
                    class="inner-input-validation-error"
                </text>
            }
        >
        @Html.EditorFor(model => model.TestValue1)
        @Html.EditorFor(model => model.TestValue2)
    
    </span>
    

    Thats it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple object like this public class Test { public string Name
I'm just wondering .. I have and object like this public class Entry{ public
I have class like the following: class test { public string Name; public string
I have a class public class ConversionResultModel { public string ProcessId { get; set;
I have this object : public class MyObject { public int Id { get;
Say I have a component like this public class MyComponent { public MyComponent(string name)
I have a JPA object which has a many-to-many relationship like this: @Entity public
In Java I have an object that looks like this : class MyDoc {
I have a model (simplified for relevance) like this: public abstract class TitleCreateModel :
I have a class structure like this public class Entity { public int Id

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.