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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:16:13+00:00 2026-05-22T00:16:13+00:00

I am building a WebPages site and have an issue when I try to

  • 0

I am building a WebPages site and have an issue when I try to pass ModelState data to a partial page.

Here is the code for Create.cshtml:

@{
    Page.Title = "Create Fund";

    var name = "";

    if (IsPost) {
        name = Request.Form["name"];

        if (!name.IsValidStringLength(2, 128)) {
            ModelState.AddError("name", "Name must be between 2 and 128 characters long.");
        }
    }
}

@RenderPage("_fundForm.cshtml", name)

Here is the code for _fundForm.cshtml:

@{
    string name = PageData[0];
}

<form method="post" action="" id="subForm">
    <fieldset>
        @Html.ValidationSummary(true)
        <legend>Fund</legend>
        <p>
            @Html.Label("Name:", "name")
            @Html.TextBox("name", name)
            @Html.ValidationMessage("name", new { @class = "validation-error" })
        </p>
        <p>
            <input type="submit" name="submit" value="Save" />
        </p>
    </fieldset>
</form>

The issue I am having is when there is an error for “name”, the validation error does not display. Is there a special way to pass ModelState between the two pages?

_fundForm is going to be shared between Create.cshtml and Edit.cshtml.

  • 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-22T00:16:14+00:00Added an answer on May 22, 2026 at 12:16 am

    ModelState is a readonly property of System.Web.WebPages.WebPage class. Its backing field is a private ModelStateDictionary and is initialized at first access. I can’t see any way to force ModelState across pages, apart from doing it via reflection as seen in SO question: Can I change a private readonly field in C# using reflection?

    Otherwise, you can simply use a third parameter in the invocation, like this:

    @RenderPage("_fundForm.cshtml", name, ModelState);
    

    In effect, the first parameter after the page name will become the Model of the new page, so there is enough space (i.e. the next parameter) to pass the ModelState.

    In your “_fundForm.cshtml” merge the ModelState received by the calling page with the local one, like this:

    @{
        //In _fundForm.cshtml
        var ms = PageData[1];
        ModelState.Merge((ModelStateDictionary)ms);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a site that is going to have a lot going on
I'm building a webpage and I'm getting the following warning (and the page loads
building a site using PHP and MySQL that needs to store a lot of
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
I'm in the process of building a mobile site (for Iphones and Androids... I
I'm building a django webpage but I seem to have hit a snag as
I have been tasked with building a new web project from scratch, with the
I'm new to website building, so I'm really struggling! I have an image of
I'm building a few webpages in my webapplication which use a webservice. While communicating
I am building a Windows Workflow into a .Net webapp. The problem I have

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.