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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:34:57+00:00 2026-05-16T07:34:57+00:00

I’ve asked a question to know why, in my application, textboxes are being highlighted

  • 0

I’ve asked a question to know why, in my application, textboxes are being highlighted (i.e. red border and pink-shaded backgroung are applied to the textbox) when I use modelbinding to validate the model (TryUpdateModel()) but not when I validate manually (ModelState.AddModelError). It has been 2 days now without any answer. I’ve tried every thing myself without succes. So, I decide to ask the question differently.

The way I understand IT, here’s how ModelBinding treats a request.

  1. ModelBinding get incoming values from httpcontext
  2. It instantiate an object of that model
  3. Tries to parse those values to the object
  4. If there’s someting wrong with a property, it uses ModelState.AddModelError to mark properties that has something wrong with them.
  5. Re-displays the view

Here’s my question When the form is re-displayed:

What’s being done for the textboxes whose values are not valid to get highlighted?

I know that there’s few classes in Site.css, such as .input-validation-error and .field-validation-error that get applied to the textbox. Maybe ModelBinding uses internally a command such as AddCss(“#MyTextBox”, “.input-validation-error”).

If I know how it works, I can (maybe) aplly it manually and solve my problem.

EDIT

As requested by @Ian Galloway, here’s the code

public class RegistrationController : Controller
{
  public FormViewModel formViewModel;
  private RegistrationService _registrationService = new RegistrationService();
  private SaveService _saveService = new SaveService();
  protected override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var serialized = Request.Form["formViewModel"];
        if (serialized != null)
        {
            formViewModel = (FormViewModel)new MvcSerializer()
                            .Deserialize(serialized);
            TryUpdateModel(formViewModel);
        }
        else
            formViewModel = (FormViewModel)TempData["formViewModel"] 
                            ?? new   FormViewModel();
    }
  protected override void OnResultExecuted(ResultExecutedContext filterContext)
    {
        if (filterContext.Result is RedirectToRouteResult)
            TempData["formViewModel"] = formViewModel;
    }
    public ActionResult SetUpOrganization(string cancel, string nextButton)
    {
        if ((nextButton != null) && ModelState.IsValid)
        {
            if (formViewModel.navigationData.IsAReview)
                return RedirectToAction("RequestPreview");
            return RedirectToAction("ChooseTypeOrganization");
        }
        ViewData["Cities"] = _registrationService.Get_Cities();
        formViewModel.navigationData.NextAction = "SetUpOrganization";
        return View(formViewModel);
    }
  public ActionResult ChooseTypeOrganization(string backButton, string nextButton)
    {
        if (backButton != null)
        {
            return RedirectToAction("SetUpOrganization");
        }
        if (nextButton != null)
        {
            if (formViewModel.navigationData.IsAReview)
                return RedirectToAction("RequestPreview");
            return RedirectToAction("DocumentsPresented");
        }
        ViewData["TypeOrganization"] = _registrationService.Get_AllTypeOrganization();
        formViewModel.navigationData.NextAction = "ChooseTypeOrganization";
        return View(formViewModel);
    }
    public ActionResult DocumentsPresented(string backButton, string nextButton)
    {
        if (backButton != null)
        {
            return RedirectToAction("ChooseTypeOrganization");
        }
        if (nextButton != null)
        {
            //Validation
            if (string.IsNullOrEmpty(formViewModel.registrationData.DocumentPresente))
            {
                ModelState.AddModelError("DocumentPresente", "Veuillez préciser votre
                  autorisation");
                return View(formViewModel);
            }
            //Navigation
            if (formViewModel.navigationData.IsAReview)
                return RedirectToAction("RequestPreview");
            return RedirectToAction("PeopleRecommended");
        }
        formViewModel.navigationData.NextAction = "DocumentsPresented";
        return View(formViewModel);
    }
  public ActionResult PeopleRecommended(string backButton, string nextButton, string deleteButton,
                                          string deletePerson, string addPerson)
    {
        if (backButton != null)
        {
            return RedirectToAction("DocumentsPresented");
        }
        if (nextButton != null)
        {
            ModelState.Clear();
            if (formViewModel.registrationData.PeopleRecommended.Count == 0)
                ModelState.AddModelError("", "Il faut absolument designer un responsable pour la requête");
            //
            if (ModelState.IsValid)
            {
                if (formViewModel.navigationData.IsAReview)
                    return RedirectToAction("RequestPreview");
                return RedirectToAction("StateObjectifs");
            }
            else
            {
                return View(formViewModel);
            }
        }
        //
        if (addPerson != null)
        {
            if (ModelState.IsValid)
            {
                formViewModel.registrationData.PeopleRecommended.Add(
                    _registrationService.Translate_PersonToBeAdded_Into_Person(formViewModel.personToBeAdded)
                    );
                formViewModel.personToBeAdded = null;
            }
            else
            {
                formViewModel.navigationData.NextAction = "PeopleRecommended";
                return View(formViewModel);
            }
        }
        if (deleteButton != null)
        {
            formViewModel.registrationData.PeopleRecommended.RemoveAt(int.Parse(deletePerson));
        }
        ViewData.ModelState.Clear();
        formViewModel.navigationData.NextAction = "PeopleRecommended";
        return View(formViewModel);
    }
    [ValidateInput(false)]
    public ActionResult StateObjectifs(string backButton, string nextButton)
    {
        if (backButton != null)
        {
            return RedirectToAction("PeopleRecommended");
        }
        if (nextButton != null)
        {
            if (string.IsNullOrEmpty(formViewModel.registrationData.Objective) ||
               string.IsNullOrEmpty(formViewModel.registrationData.RequestDetails))
            {
                 if (string.IsNullOrEmpty(formViewModel.registrationData.Objective))
                     ModelState.AddModelError("Objective", "Vous devez préciser l'objectif de votre requête");

                 if (string.IsNullOrEmpty(formViewModel.registrationData.RequestDetails))
                     ModelState.AddModelError("RequestDetails", "Vous devez préciser le contenu de votre requête");
                 return View(formViewModel);
            }

            if (formViewModel.navigationData.IsAReview)
                return RedirectToAction("RequestPreview");
            return RedirectToAction("StateDeadLine");
        }
        return View(formViewModel);
    }

    public ActionResult StateDeadLine(string backButton, string nextButton)
    {
        if (backButton != null)
        {
            return RedirectToAction("StateObjectifs");
        }
        if (nextButton != null)
        {
            if (formViewModel.registrationData.ChooseDifferentDeadLine)
            {
                if (formViewModel.registrationData.DifferentDeadline == null ||
                    string.IsNullOrEmpty(formViewModel.registrationData.ReasonsForDifferentDeadLine))
                {
                    if (formViewModel.registrationData.DifferentDeadline == null)
                        ModelState.AddModelError("DifferentDeadline", "Clickez pour choisir une nouvelle date");
                    if (string.IsNullOrEmpty(formViewModel.registrationData.ReasonsForDifferentDeadLine))
                        ModelState.AddModelError("ReasonsForDifferentDeadLine", "Expliquez brievement pour quoi ce changement");

                    return View(formViewModel);
                }
            }
            return RedirectToAction("RequestPreview");
        }
        formViewModel.navigationData.NextAction = "StateDeadLine";
        return View(formViewModel);
    }
  public ActionResult RequestPreview(string backButton, string nextButton, string reviewInput, string save)
    {
        if (backButton != null)
        {
            return RedirectToAction("StateDeadLine");
        }
        if (nextButton != null)
        {
            _saveService.Save_FormViewModel(formViewModel);   
            return RedirectToAction("Index", "Home");
        }
        if (reviewInput != null)
        {
            formViewModel.navigationData.IsAReview = true;
            return RedirectToAction(RedirectHelpers.RedirectReviewAction(formViewModel.navigationData, reviewInput));
        }
        ViewData["TypeOrganization_Summary"] = _registrationService.Get_TypeOrganization_Summary(
                                                                formViewModel.registrationData.TypeOrganizationID                                                                   );
        if (save != null)
        {
            _saveService.Save_FormViewModel(formViewModel);
            return RedirectToAction("Index", "Home");
        }

        formViewModel.navigationData.NextAction = "RequestPreview";
        return View(formViewModel);
    }
}

EDIT number 2

I have choosed one of the view (as all of them experience the same issue). The view is called StateObjectifs.aspx

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<!-- Script Begin -->
<script src="../../Scripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>
<script type = "text/javascript">
    tinyMCE.init({
        mode: "textareas",
        theme: "advanced",

        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",
        theme_advanced_resizing: true
    });
</script>
 <!-- End Script -->
<fieldset id = "StateObjectifs">
    <legend>Etape 5:</legend>
    <div id = "left-pane" style = "width:700px">
    <%using (Html.BeginForm("StateObjectifs", "Registration"))
  { %>
   <%: Html.ValidationSummary() %>
  <% = Html.Serialize("formViewModel", Model) %> 
  <table>
    <tr>
        <th><% = Html.LabelFor(x=>x.registrationData.Objective) %></th>
        <td><% = Html.TextBoxFor(x=>x.registrationData.Objective) %>
            <%: Html.ValidationMessageFor(x =>x.registrationData.Objective, "*")%></td>
    </tr>
    <tr>
        <th colspan = "2"><% = Html.LabelFor(x =>x.registrationData.RequestDetails) %></th>
    </tr>
    <tr>
        <td colspan = "2">
            <% = Html.TextAreaFor(x =>x.registrationData.RequestDetails, 10, 75, null) %>

        </td>
    </tr>
  </table>
  </div>
  <div id = "right-pane">
        <ul>
            <li>Les cases pour lesquelles le titre se termine par (*) sont obligatoires</li>
            <li>Pour mieux vous servir, veuillez décrire clairement de manière concise
                votre requête. Par exemple: <i>Les données de l'USAID sur le secteur santé pour l'année 2009</i></li>
        </ul>  
      </div>
      <div class = "clear"></div>

  <fieldset>
            <% Html.RenderPartial("NavigationView", Model.navigationData); %>
  </fieldset>
</fieldset>
<%} %>

Thanks for helping.

  • 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-16T07:34:57+00:00Added an answer on May 16, 2026 at 7:34 am

    Actually this highlighting is performed by the html helpers that render the textboxes. It checks if there’s an error in the model state with the given key and it adds the necessary CSS classes if necessary.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
Does anyone know how can I replace this 2 symbol below from the string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.