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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:33:49+00:00 2026-05-19T02:33:49+00:00

I am starting a new project in Asp.net MVC 2. I have been mostly

  • 0

I am starting a new project in Asp.net MVC 2.
I have been mostly a webforms developer and have limited exposure to Asp.Net MVC and hence this is probably a noob question.

My situation is as follows:
I have a create page for saving some data to the DB.
The view for this page is not strongly bound / typed – so the way I am extracting the data from the view is by looking at the POST parameters.

Incase there is an error (data validation, etc), I need to send the user back to the previous page with everything filled in the way it was and displaying the message.

On webforms, this got handled automatically due to the view state – but how can I go about doing the same here?

A code example can be as follows:

View:

<% using (Html.BeginForm("Create", "Question", FormMethod.Post)) { %>
<div>
Title: <%: Html.TextBox("Title", "", new { @style="width:700px" })%>
</div>
<div>
Question: <%: Html.TextBox("Question", "", new { @style="width:700px" })%>
</div>
<input type="submit" value="Submit" />
<% } %>

Controller:

    [HttpPost]
    [ValidateInput(false)]
    public ActionResult Create() {
        Question q = new Question();
        q.Title = Request.Form["Title"];
        q.Text = Request.Form["Question"];
        if(q.Save()) {
            return RedirectToAction("Details", new { id = q.Id });
        }
        else {
            // Need to send back to Create page with data filled in
            // Help needed here
        }
    }

Thanks.

  • 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-19T02:33:50+00:00Added an answer on May 19, 2026 at 2:33 am

    You could simply return the View in case of error. This will preserve the context.

    [HttpPost]
    [ValidateInput(false)]
    public ActionResult Create(Question q) {
        if(q.Save()) {
            return RedirectToAction("Details", new { id = q.Id });
        }
        else {
            // Need to send back to Create page with data filled in
            // Help needed here
            return View();
            // If the view is located on some other controller you could
            // specify its location:
            // return View("~/Views/Question/Create.aspx");
        }
    }
    

    Also I would recommend you to use strongly typed views along with the strongly typed helpers. Notice how I used a Question object directly as action parameter. This is equivalent to the code you have written in which you were manually extracting and building this object. The model binder does this job automatically for you.

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

Sidebar

Related Questions

No related questions found

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.