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

  • Home
  • SEARCH
  • 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 830583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:04:04+00:00 2026-05-15T04:04:04+00:00

I have a form which a user can fill in x times with the

  • 0

I have a form which a user can fill in x times with the data they want too. The form is posted to the following Action.

        [HttpPost]
        public ActionResult Manage(ProductOptionModel DataToAdd)
        {
            if (!ModelState.IsValid)
            {
                return View(DataToAdd);
            }

            var ProdServ = new ProductService();

            if (DataToAdd.ID != 0)
            {
                //Edit Mode.
                DataToAdd = ProdServ.EditProductOption(DataToAdd);
                ViewData["Message"] = "Option Changes Made";

            }else
            {
                //Add
                DataToAdd = ProdServ.AddProductOption(DataToAdd);
                ViewData["Message"] = "New Option Added";
            }

            var RetModel = new ProductOptionModel() {ProductID = DataToAdd.ProductID};
            return View(RetModel);
        }

So at the bottom I blank the model (Leaving just the required field) and then return to the view. However the view holds the data from the previously submitted form.

Any ideas why? I have debugged the code and checked that the RetModel variable is empty.

  • 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-15T04:04:05+00:00Added an answer on May 15, 2026 at 4:04 am

    Html helpers work this way when a view is returned on HTTP POSTs. They prefer post data over model values.

    Use Post/Redirect/Get

    That’s why I suggest you use the Post/Redirect/Get pattern that’s very well supported in Asp.net MVC. Your controller actions should redirect to some GET action after POST has successfully completed as it is in your case.

    public ActionResult Process()
    {
        return View(new Data { Id = -1 });
    }
    
    [HttpPost]
    public ActionResult Process(Data data)
    {
        if (!this.ModelState.IsValid)
        {
            return View(data);
        }
        new MyService().ProcessData(data);
        return RedirectToAction("Process");
    }
    

    And if you display all previously entered data you can provide those in in the GET action or transfer them from POST to GET action using TempData dictionary.

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

Sidebar

Related Questions

I have a form into which the user can add more fields to fill
I have a form where the user can fill in the fields with data.
We have a form on our website in which a user can fill out
I have a CCK field price which the user can fill in. I would
i have an user form which he has to fill before moving on to
I have been struggling to create a django form which users can fill and
I have a form that a user can fill out that maps to an
I have about 20 text fields on a form that a user can fill
I have a form where users can pick several locations they want to stay
I have a HTML form which allows a user to add rows ad hoc

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.