Avatar of MRS
MRS
Flag for United States of America asked on

Asp.NET Core post form from a layout page to a child page

I an new to ASP.NET CORE Razor Pages & MVC, but very familiar with WebForms (so bear with me).  I am trying to create a web site using Razor Pages.  I have a layout pay that contains the main navbar and footer. In the navbar has simple search controls where a user can enter a 2 values, and click the search button.  I have a child page that handles the search (and also has more expanded search functionality)

How can go about passing the values from the layout page controls and redirecting them to the child page.  I have searched around and come up with this, but it doesn't seem to be working?  Am i way off base?

 @using (Html.BeginForm("~/v1/Agent/Search", "RemoteSearch", FormMethod.Post, new { @class = "form-inline my-2 my-lg-0" }))
            {
                SearchModel searchModel = new SearchModel();
                @Html.AntiForgeryToken();
                @Html.DropDownListFor(x => searchModel.searchID, new SelectList(AccountSearch.GetSearches(), "searchID", "name"), htmlAttributes: new { @class = "form-control mr-sm-2" });
                @Html.TextBoxFor(x => searchModel.searchValue1, htmlAttributes: new { @class = "form-control mr-sm-2" });
                <button type="submit" class="btn btn-secondary my-2 my-sm-0">Search</button>
            }

Open in new window

* asp.net core mvcC#* Razor

Avatar of undefined
Last Comment
MRS

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ioannis Paraskevopoulos

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ambience

"~/v1/Agent/Search" is not a valid action name or is it?

Given a controller class RemoteSearch with Action "Search" The first paramter to BeginForm should be "Search". If the method is Index, this should be "Index".

If you are submitting to Controller "Agent" Action "Search" then do it like

BeginForm("Search", "Agent" ....
MRS

ASKER
thanks for all the detail that really helps..
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy