I am trying to get some more information about Razor Pages with core 2.0 and I am having some issues with the post. Please note, this is not production worthy, its just code to try and getting a better understanding of what you can do in razor pages.
The issue is, if my button is in the form, it does not send any data back to the view. So, computedURL in OnPostConcatURL() is never getting to the view.
If the button is outside the form, the form data does not get to the post controller OnPostEdit23 but I can send back ComputedURL to the view. Clearly I am missing something or a lot. And I cannot find an example to fix this.
@page
@model VisibilityTest
@{ ViewData["Title"] = "Visibility Test Site"; }
<form id="frmVisibility" method="post">
<div class="container">
<div class="row form-group">
<div class="col-md-1"> Select Portal: </div>
<div class="col-md-1"><select id="ddlEnvironment" asp-for="selectedEnvironment" asp-items="Model.Environments"></select></div>
<div class="col-md-2"><select id="ddlPortalName" asp-for="selectedPortalName" asp-items="Model.portalNames"></select></div>
<div class="col-md-3"><input asp-for="@Model.ComputedURL" /></div>
</div>
<div class="row form-group">
<div class="col-md-1"><button id="btnConcatURL" asp-page-handler="ConcatURL" type="submit" class="btn btn-primary">Submit23</button></div>
</div>
</div>
</form>
<form method="post">
<button asp-page-handler="edit23" class="btn btn-default">Edit2</button>
</form>
[BindProperty]
public string ComputedURL { get; set; }
public void OnGet()
{
config = GetConfigFile();
PopulatedEnvironmentSelectList();
PopulatePortalNameSelectList(config);
}
public IActionResult OnPost()
{
ComputedURL = selectedEnvironment + selectedPortalName;
return RedirectToPage("./VisibilityTest");
}
public void OnPostConcatURL()
{
ComputedURL = "this is a test";
}
public void OnPostEdit23()
{
ComputedURL = "this is a test";
}
I'm still figuring out Razorpages as well but I noticed a couple of points about your example:
So your example modified example below seems to do what you are looking for (I simplified the dropdowns to text fields for easy testing).
.cshtml page
.cshtml.cs page: