MVC Post question

In the controller...

        [HttpPost]
        public ActionResult CreateContinent(string Name, string Area, string Highpoint,
           string Height, string Lowpoint, string Depth)
        {

            Mvc3Application1.Models.Continent ctnt = new Mvc3Application1.Models.Continent();
            //Mvc3Application1.Models.Continent ctnt = c.GetContinents(sContinent);

            ctnt.Name = Name;
            ctnt.Area = Convert.ToInt64(Area);
            ctnt.Highpoint = Highpoint;
            ctnt.Height = Convert.ToInt64(Height);
            ctnt.Lowpoint = Lowpoint;
            ctnt.Depth = Convert.ToInt64(Depth);
            Mvc3Application1.Models.GetContinent d = new Mvc3Application1.Models.GetContinent();
            if (d.CreateContinent_data(ctnt) > 0)
            {
                ctnt.Name = "Success";
            }
            return View(ctnt);
        }

In the view...
        <div class="editor-field">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </div>

The view is persisting the originally entered value not the value of Success even when the object property is set to success prior to passing the object back to the view.

Can anyone help?

Thanks!
gswitzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gswitzAuthor Commented:
I recognize that my post might not have been clear enough.

I have a view typed on a class (strongly typed). The view is for creating new items. On the httpget in the controller, I can new up the class the view is typed on, set some values and return it to the view, setting default values in the text boxes.

The user can then set values in the text boxes and click a button to post back.

The httppost method in the controller catches it with every value as an input parameter in the signature. I then Insert the data into the database.

I want to clear the values returned to the view, so I new up a new instance of the class, set the values and return it to the view.

The problem is this...
The values displayed on the page are the same as what the user entered, not the cleared values I passed from the controller to the view.

...
It seems like there might be a page is dirty or something? I don't know...
It's strange that when I pass it from the httpget and step through the view, the values are set in the fields, but when I pass it from the post to the view, model.Name has a does not exist or cannot be found or something... I don't know why.

Any thoughts?
0
gopaltaydeCommented:
My guess is that the below condition is returning false

            if (d.CreateContinent_data(ctnt) > 0)
            {
                ctnt.Name = "Success";
            }

hence it is not updating then name. Try to debug the code or write the else part.

But generally, we should return to index page after adding something by using -

return RedirectToAction("Index");
0
gswitzAuthor Commented:
Actually, I stepped through it and it returns true and executes the line

ctnt.Name="Success";

So, I can't really explain it. It's like I need to set a page is dirty property or something so that it will repaint. I have no idea.
0
gswitzAuthor Commented:
Using

ModelState.Clear();

Solves the problem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gswitzAuthor Commented:
My answer is the right answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.