Link to home
Start Free TrialLog in
Avatar of MRS
MRSFlag 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

ASKER CERTIFIED SOLUTION
Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"~/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" ....
Avatar of MRS

ASKER

thanks for all the detail that really helps..