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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:12:58+00:00 2026-05-28T13:12:58+00:00

I am checking a model for validity in an action. The repository throws various

  • 0

I am checking a model for validity in an action. The repository throws various exceptions depending on how the checks I carry out go, so the action contains a try-catch statement.

[AcceptVerb(HttpVerbs.Post)]
public ActionResult MyAction1(Action1Model Model)
{
    if (ModelState.IsValid)
        try
        {
             new MyModelRepository().CarryOutSomeChecks(Model);
             return View("SuccessfulView")
        }
        catch (ValidationException)
        {
             Model.Result = Result.Fail;
             ModelState.... <= I would like to reset the ModelState here.
        }
    return View(Model)
}

The view model contains some sensitive information, so if the checks fail I would like to return to the view and remove the values which were input by the user.

To complicate things in my view I call actually has two partial views in it that show a form each, so like:

@model MyProject.MyOverallViewModel
@{
}

@{Html.RenderPartial("MyAction1Form", Model.Action1ModelInstance);}
@{Html.RenderPartial("MyAction2Form", Model.Action2ModelInstance);}

I have tried doing Model = new Model() in the catch, but, even though the model passed to the view is all null, the values entered to the form are persisted. I assume this is because of ModelState… Is there a way to reset that?

I would like to avoid doing a RedirectToAction so that I can persist the result of my check within my model when the view is displayed again.

Any ideas?

  • 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-28T13:12:58+00:00Added an answer on May 28, 2026 at 1:12 pm

    ModelState.Clear(); should do the job.

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

Sidebar

Related Questions

After checking out code for the first time from a repository into Eclipse using
After checking out a branch in a repository git always prints a list of
What types of applications have you used model checking for? What model checking tool
we are working on a model checking tool which executes certain search routines several
Is it a good practise to decouple input checking from a model and have
I was checking out the source on an html page and came across this
I have a Model which contains an Address and Person twice, once for the
I have an object model where I'm checking a filter value of nested child
I was checking out this link: http://blogs.msdn.com/b/stuartleeks/archive/2011/01/25/asp-net-mvc-3-integrating-with-the-jquery-ui-date-picker-and-adding-a-jquery-validate-date-range-validator.aspx which describes creating a jquery datepicker for
I need to validate a model only for a certain action (:create). I know

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.