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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:43:21+00:00 2026-05-22T11:43:21+00:00

So what I do is, I have a controller that checks if the input

  • 0

So what I do is, I have a controller that checks if the input in my form is correct. If it’s not, it puts an error message in the ViewBag and returns the view. Like this (unimportant stuff left out):

var name = formCollection.Get(cr.Category.name + "-name-" + i).Trim();
var dateOfBirth = formCollection.Get(cr.Category.name + "-dateOfBirth-" + i).Trim();
var passportno= formCollection.Get(cr.Category.name + "-passportno-" + i).Trim();

if (name.Equals("") || dateOfBirth.Equals("") || passportno.Equals(""))
{
     ViewBag.ErrorMessage = "Please fill in all required fields at " + cr.Category.naam;
     return View("BulletinForm3");
}

And my view looks like this (unimportant stuff left out):

<input name="@(cr.Category.naam)-name-@i" value="" />
<input name="@(cr.Category.naam)-dateOfBirth-@i" value="" />
<input name="@(cr.Category.naam)-passportno-@i" value="" />

@if (ViewBag.ErrorMessage != null)
{
     <p class="error">@ViewBag.ErrorMessage</p>
}

So what happens when you forget to fill in a required field? It returns the view and displays the error message, BUT all the fields that were already filled in are empty again… So what I want to do is use the FormCollection to fill them back in after it returns the view. I put the FormCollection in the ViewBag like this:

ViewBag.ErrorMessage = "Please fill in all required fields at " + cr.Category.naam;
ViewBag.FormCollection = formCollection;
return View("BulletinForm3");

And changed this in the view:

<input name="@(cr.Category.naam)-name-@i" value="@if (ViewBag.FormCollection != null) { ((FormCollection)ViewBag.FormCollection).Get(cr.Category.naam + "-name-" + i);}" />

However, it doesn’t fill in the input fields with the values of the FormCollection… The FormCollection isn’t empty (tested it) and the names are the same (the counter (i) doesn’t change or something).
What am I doing wrong?

Thanks in advance

  • 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-22T11:43:23+00:00Added an answer on May 22, 2026 at 11:43 am

    As I couldn’t find a solution, I decided to use Javascript validation instead of validating in the controller. Now, there is no postback so no need to fill the fields in again.

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

Sidebar

Related Questions

I have parent view that also renders sub-controller action using RenderAction() (that returns a
I have a controller action that checks this.User.Identity.IsAuthenticated What do you suggest how to
I have a controller method that returns a jSON object and in one calling
I have a Spring controller that returns XHTML, what's the easiest way to setup
I have a simple form that I would like to validate on form submission.
I'm creating a login form with Codeigniter, and I have a controller that collects
I have a user controller that checks to login a user. It has this
I have a MVC application that receives an input from a form. This is
I have a controller that contains a tableView that spawns another controller modally to
I have a controller that is called with AJAX (sends JSON data), so I

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.