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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:03:39+00:00 2026-06-13T20:03:39+00:00

Here is one of the examples that I’ve seen on how to do validation

  • 0

Here is one of the examples that I’ve seen on how to do validation on Controller:

[HttpPost]
public ViewResult Create(MyModel response)
{
    if (ModelState.IsValid)
    {
        return View("Thanks");
    }
    else
    {
        return View();
    }
}

If there are validation errors, than return View() method is called without any parameters. Obviously you have @Html.ValidationSummary() in your View and Model has all required property attributes.

The data that was entered into the form was preserved and displayed again when the view was rendered with the validation summary.

My question: how is the data preserved? Since it was not passed to the View like

return View(response);

Thanks a lot.

Sincerely,
Vlad

  • 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-13T20:03:40+00:00Added an answer on June 13, 2026 at 8:03 pm

    It is because the values have been bound to the model state which is passed back along to the view. This is along the same issue/question on why you cannot change a model value and return the view again. Meaning, let’s assume I have the following property on my Viewmodel

    public string Name {get;set;}
    

    Using the controller below, I cannot change the ViewModel property without also either clearing the ModelState or updating the value in the model state. Try it!

    [HttpPost]
    public ViewResult Create(MyModel response)
    {
        response.Name = response.Name + "Some Random String"
        return View();
    }
    

    The name property will remain unchanged. Essentially, once the ModelBinding occurs, the values from your form (ViewModel) are bound to the model state, which is why you do not have to pass the model back to the view.

    As a side note, I always pass the model back in my call to return View();, it just seems more correct and a little easier to read

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

Sidebar

Related Questions

I tried one of the examples here to load the content in the div,
Here one more basic question asked in MS interview recently class A { public
Here is one of my Entityclasses: public class Customer { public int Id {
Interesting one here. I have an ASP.NET 1.1 project that contains a web service
The majority of pyparsing examples that I have seen have dealt with linear expressions.
Is it just me or literally ALL the examples that I have seen on
I have tried the code examples that I found here on the stackoverfllow site,
i am trying one example from Here for ontouch image zoom and touch on
Here is an example of one of our data calls in our DAL using
Here is one I am working on: var fStep = from insp in sq.Inspections

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.