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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:29:39+00:00 2026-05-13T22:29:39+00:00

I have an ASP.NET MVC form that when submitted can return either an ActionResult

  • 0

I have an ASP.NET MVC form that when submitted can return either an ActionResult if there was an error with the data, or if everything is fine it redirects to a different action that returns a FileResult.

I’ve created a bit of a sample to provide an idea of what I am doing. This is the html:

<%
using (Html.BeginForm())
%>
    <%= Html.ValidationSummary(
        "Edit was unsuccessful. Please correct the errors and try again.") %>
    <%= Html.TextBox("YourName", Model.YourName)%>
    <%= Html.ValidationMessage("YourName", "*") %>
    <input type="submit" />
<% } %>

and the controller code is:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult MyPostSample(string YourName)
{
    if (string.IsNullOrEmpty(YourName))
    {
         ModelState.AddModelError("YourName", "You must specify a name");
    }

    if (ModelState.IsValid)
    {
         // get the file
         RedirectToAction("GetFile");
    }
    else
    {
         // return this actions View with errors
         return View();
    }
}

public FileResult GetFile(string YourName)
{
    // return file here
}

The reason for the ActionResult is to populate ModelState errors so the user can correct and try again.

This all works fine, except I would like the form to be reset or cleared if a file is returned by the server. Currently the user gets a File dialog, but the form retains the submitted values. What can I do to reset the form after a successful submit?

  • 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-13T22:29:40+00:00Added an answer on May 13, 2026 at 10:29 pm

    I would recommend returning a new form with a bit of javascript that triggers the download (along with a link to use if the download doesn’t start). I feel that this is the best way to make sure that it works both with and without javascript and gets you the sort of behavior that you desire.

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

Sidebar

Related Questions

I have a form that collects a data using ASP.NET MVC. It looks like
I am using ASP.NET MVC 1.0. I have an ActionResult which receives a form
I have a simple form on an ASP.NET MVC site that I'm building. This
I have an ASP.NET MVC 2 form that is working perfectly, doing client side
I have a problem on submitting an asp.net mvc form that is using Xval
I'm using asp.net mvc 3 with unobtrusive jquery validation. I have a form that
Hello is it possible to have an ASP.NET MVC form that uses the routes
In ASP.NET MVC, I have a main standard form that posts to an action,
I have an ASP.NET MVC project with a form. In the Action method that
I have an ASP.NET MVC form that may (usually does) submit a response that

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.