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.