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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:04:01+00:00 2026-06-07T16:04:01+00:00

The following are two examples of a controller for submitting data. One returns the

  • 0

The following are two examples of a controller for submitting data. One returns the input model if validation fails the other doesn’t. Can someone enlighten me on which is method correct or preferred? They seem to behave exactly the same.

With returning model

    [HttpPost]
    public ActionResult Register(RegisterModel model)
    {
        if (ModelState.IsValid)
        {
    //do stuff
        }


        return View(model);
    }

Without returning model

    [HttpPost]
    public ActionResult Register(RegisterModel model)
    {
        if (ModelState.IsValid)
        {
    //do stuff
        }


        return View();
    }
  • 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-07T16:04:03+00:00Added an answer on June 7, 2026 at 4:04 pm

    Usually you want the user to show an error message if the data he submitted is not valid (e.g. he did not enter a valid email address into a field that requries to be an email – see MVC ModelValidation for more information).

    You use the ModelState.IsValid to check for that. In this case you usually show him the page he came from (“Register”) and you also want to show the data he entered into the form fields (= RegisterModel). But you want to display an errormessage that tells him what fields are not correct.

    If the user’s data is correct and your action succeeds (in this case he was registered successfully) you usually do not show him the registration form again, but you would redirect him to a success page.

    Here is a simple example how to validate, show errors and redirect after successfull action.

    Example from your code:

    [HttpPost]
    public ActionResult Register(RegisterModel model)
    {
        if (ModelState.IsValid)
        {
           //do stuff
           // redirect to a success page
           return RedirectToAction("Success");
        }
    
        // data is not valid - show the user his data and error messages
        // using Html Helper methods (see link for details)
        return View(model);
    }
    

    On the Register view (Ifno – if you have a strongly typed view, you can use the HTML Helper overloads for that – e.g. use Html.LabelFor, TextboxFor etc methods):

    Show general error message/summary;

    ...
    <%= Html.ValidationSummary("Register was not successfull") %>
    

    Show error message next to the inputs:

    ...
    <%= Html.TextBox("Email") %>
    <%= Html.ValidationMessage("Email", "*") %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any difference between the following two examples and should one be preferred
I have the following two actions in my controller: function add() { if (!empty($this->data))
In the following example I have two years worth of data denoted by data_2007
Given the following HTML example... <div id='div1'>div one</div> <div id='div2'>div two</div> ...I found that
How do I create an xsd that can validate either of the following two
I have the following two routes in my app: Router::connect('/posts/:id', array('controller' => 'posts', 'action'
Two part question. How do I get the post data in the controller the
For example suppose I have the following two functions function a(param1) { console.log(param1); }
Say for example, I have the following two tables: TableA { _id } TableB
For example, let's say I have the following two tables: Table1: Id ---- 1

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.