How to temporary store in form data in .NET core - asp.net-mvc

I am learning ASP.Net Core and I am creating a mock Flight booking app. On my home page, I have a search form to find a flight.
On submitting my form it goes to my SearchResultsController and then to my Search() action where I will run a search query.
What's the best way to pass the parameters through to this controller action for use in the Search() action method?
All the methods I've seen this far have involved creating new models but I don't want to save the searches to my database as it's not information that needs retaining. Having come to form a rails background I would use the parms hash which is a temporary data store.
Form:
<form asp-controller="SearchResults" asp-action="Search" method="post">
<div class="form-group">
<label for="fromAirport">Flying from:</label>
<select asp-for="AirportId" asp-items="#(new SelectList(ViewBag.ListOfAirports, "AirportId", "AirportCode"))" class="form-control">
</select>
<div class="form-group">
<label for="toAirport">Flying to:</label>
<select asp-for="AirportId" asp-items="#(new SelectList(ViewBag.ListOfAirports, "AirportId", "AirportCode"))" class="form-control">
</select>
</div>
<label for="fromAirport">Departure Date:</label>
<br />
<input type="date" />
<br />
<label for="fromAirport">No. passengers:</label>
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<button type="submit" class="btn btn-primary mt-3">Search Flights</button>
</div>
</form>

Related

HTML - "Search by" and how to filter by selected field

My task is to add a combo-box in the search page to allow a user to select the field she wants to search by and then search for customers using that field. In other words, there should be a “Search By” combo-box on the index page that the user selects the field to search by (Last Name, First Name, etc.) and then types in a search string and clicks a find button to perform a search and display the results on the same page. Search results should be sorted based on the field used for the search.
Currently, I have the following code:
<form asp-action="Index" method="get">
<div Class="form-actions no-color"></div>
<div class="search-item">Search</div>
<div class="sigform_fld search-item">
<select class="catalog">
<option value="1">Customers</option>
</select>
</div>
<div class="search-item">By</div>
<div class="sigform_fld search-item option">
<select class="option-1">
<option value="2">Last Name</option>
<option value="3">Email Address</option>
<option value="4">Company Name</option>
</select>
</div>
</form>
<form asp-action="Index" method="get">
<div Class="form-actions no-color">
<p>
<input type="text" name="LastName" value="#ViewData("currentFilter")" />
<input type="submit" value="Search" class="btn btn-default" />
| #Html.ActionLink("All Customers", "Index")
</p>
</div>
</form>
This only filters by Last Name. How can I have one search bar that filters by the selected option (Last Name, Company Name or Email address).
Help!

Submit button does not submit form data in bootstrap

I am trying to submit a form in a bootstrap framework and cannot get past the validation, even with correct data.
I think there might be an error with this syntax,
<form name=form1 method=post action=signupck.php onsubmit='return validate(this)'><input type=hidden name=todo value=post>
then the form fields... which all display correctly - so no problems there - in the style:
<div class="row">
<div class="col-xs-2">
<label for="fname">Forename</label>
<input type="text" class="form-control" id="fname" placeholder="Forename"><br></br>
</div>
<div class="col-xs-2">
<label for="sname">Surname</label>
<input type="text" class="form-control" id="sname" placeholder="Surname">
</div>
</div>
and then,
<input type=submit value=Signup>
<input type="reset" class="btn btn-default" value="Reset">
The form on submission displays signupck.php, signalling validation messages when is should be submitted ok. I have got this working outside the bootstrap, but when I put this inside the template, in the form above, I get the problems.
Any help would be most appreciated.

Acts-as-Taggable in Rails 4 won't work properly

I am using the acts-as-taggable gem in a Rails 4 app with an angular frontend. If I use the console it works fine. I have done all the obvious things and I can get it to work by adding this to the create controller:
if params[:tag_list]
droplet.tag_list.add(params[:tag_list], parse: true)
end
The problem is that it should be doing this anyway. Does anyone have any insight as to why it is simply not firing the tag_list.add method automatically? I am uncomfortable using this hack to get it to work.
And yes, I have added :tag_list to the strong parameters.
Update: The form html
<form ng-submit="createNewDropletForm.$valid && createNewDroplet()" name="createNewDropletForm" novalidate>
<div class="form-group">
<label for="name">Title:</label>
<input ng-keyup="keyup()" ng-model="drop.name" ng-model-options="{ debounce: 500 }" type="text" class="form-control" placeholder="Add Droplet Title Here" required>
</div>
<div class="form-group">
<label for="description">Description:</label>
<textarea class="form-control" rows="4" ng-model="drop.description" placeholder="Add helpful description of what this droplet tests." required></textarea>
</div>
<div class="form-group">
<label for="tags">Tags:</label>
<input class="form-control" ng-model="drop.tag_list" placeholder="add tags separated by commas">
</div>
<button type="submit" class="btn btn-default">Next</button>
</form>

Rails mechanize gem - scraping

I want to fill in some options which trigger the downloading of a file, using the Mechanize gem.
The HTML is the following.
<div>
<form action="" id="label_selectors" method="post">
...
...
<div class="source form_options">
<select name="source" id="source">
<option value="btce" selected="selected">Btc-e</option>
<option value="cryptsy">Cryptsy</option>
<option value="796">796</option>
<option value="bitstamp">Bitstamp</option>
<option value="formulas">Altcoin Indexes</option>
</select>
</div>
<div class="label form_options">
<select name="label" id="label">
</select>
</div>
<div class="period form_options">
<select name="period" id="period">
<option value="15m">15 minute</option>
<option value="1h" selected="selected">1 hour</option>
<option value="1d">1 day</option>
</select>
</div>
<div class="presense form_options">
CSV: <input type="radio" name="presence" value="csv"> Chart: <input type="radio" name="presence" value="chart" checked="checked">
</div>
<div class="submit form_options">
<input type="submit" name="submit" value="OK">
</div>
</form>
</div>
I tried to do something like this:
form = page.forms.first
form.source = "btce"
form.label = "BTC/USD"
form.period = "1d"
form.presense = "csv"
form.submit
However, it doesn't work:
NoMethodError: undefined method `presense=' for #<Mechanize::Form:0x007fb878dc7f98
(the typo presense rather than presence appears in the page)
How could I fill in this form correctly?
It looks like the presence input is a radio button.
To select a radio button with mechanize you'll want something like:
form.radiobuttons_with(name: 'presence')[0].check
There's other ways to select radio buttons with mechanize - you can see them here: http://docs.seattlerb.org/mechanize/GUIDE_rdoc.html

ASP.Net MVC 4 C# login form with PhantomJS and Selenium

I have a specific question, as i can't figure out how to submit form without "id" or "name" in selenium.webdriver (phantomjs) there is html logim form:
<div class="ui-helper-child-2 ui-page-column-last ui-page-column-span-12">
<div class="ui-page-column-block ui-widget-signin">
<h1>Sign In</h1>
<form action="/glo/en-us/session,create/view.html" method="post">
<div class="ui-helper-child-1">
<label class="ui-state-required" for="username">Customer ID:</label>
<input id="username" name="username" maxlength="9" type="text" value="" />
</div>
<div class="ui-helper-child-2">
<label class="ui-state-required" for="password">Password:</label>
<input id="password" name="password" maxlength="20" type="password" value="" />
</div>
<div class="ui-helper-child-3">
<label class="ui-state-required" for="companyId">Company:</label>
<select id="companyId" name="companyId">
<option selected="selected" value="glo">Choose company</option>
<option value="asp">new to asp</option>
<option value="aeg">who is it</option>
<option value="asus">who use this brand name</option>
</select>
</div>
<div class="ui-helper-child-4">
<input id="callback" name="callback" type="hidden" value="/glo/en-us/home,show/view.html?error=1" />
<input type="submit" value="Sign In" />
</div>
</form>
</div>
and one more time how to login? I can add information to by webdriver.FindElement(username) and so on, but not know how to post data as i don't have id or name in submit element.
I think this will work for you:
driver.FindElement(By.CssSelector(".ui-helper-child-4>[type='submit']")).Click();

Resources