I am using puppeteer in trying to find the selector for a login page.
the login html is:
<form action="/login?app=LM&var=au" method="POST" name="login-form" id="login-form">
<input type="hidden" name="_csrf" value="BQ2YoR3d-5P__6b5HfqlVOjv8YgTypKV92XA" />
<div class="form-group text-center">
<input type="text" name="username" id="login-form-username" placeholder="Username" class="form-control" required value="">
</div>
<div class="form-group text-center">
<input type="password" name="password" id="login-form-password" placeholder="Password" class="form-control" required>
</div>
<div class="text-center">
<button type="submit" class="btn btn-danger btn-lg btn-block">Login</button>
</div>
</form>
I tried #submit, #login-form-submit and several others for the selector. what would the selector for the login button be as there is no ID name?
i am using ClickAsync();
Either give your submit button an id property and use the #submit selector you previously tried:
<button id="submit" type="submit" class="btn btn-danger btn-lg btn-block">Login</button>
Or use form button[type=submit] as selector.
Related
I am using the tag helper normaly like this:
<a asp-action="ActionName" asp-route-id="#item.id" class="btn btn-sm btn-info mt-2">Edit</a>
or <button asp-action="ActionName" asp-route-id="#item.id class="btn btn-sm btn-info mt-2""></button>
However, when I try to use the tag helper with a composite primary key I am unable to get the link right.
asp-route-id="#item.ID1, #item.ID2" = ActionName/Id1,Id2
asp-route-id="#item.ID1?ID2=#item.ID2" = ActionName/Id1%3FID2%3DId2?
How can I use the asp-route-id and have it putput /Id1?ID2=Id2 or /Id1?{SpecifiedName}=Id2?
I found a workarout for anchor using Html.ActionLink, but not for button
This is a working demo.
<form method="post">
<label>Username:</label>
<input type="text" name="username" class="form-control" />
<label>Password:</label>
<input type="password" name="password" class="form-control" />
<button asp-action="Index" asp-route-id="1" asp-route-id2="2" class=" btn btn-info ">Edit</button>
</form>
View:
After submit the button, the generate url:
https://localhost:5001/Home/Index/1?id2=2
The request payload:
Controller action:
I want to make a form with two pages for a models class Student. I am currently trying to pass the data from first page into a controller which will pass the student as a model to my second page view which will then pass to the controller to save to my database but only the data from the second page is being saved to DB.
Page 1
#model Student
<body>
<div class="container1">
<form asp-action="Page2" method="post" role="form">
<div class=" form-group row">
<label asp-for="FirstName" class="col-md-2 control-label"></label>
<div class="col-md-5">
<input asp-for="FirstName" class="form-control" />
</div>
</div>
<div class="form-group row">
<div class="col-md-offset-2 col-md-5">
<input type="submit" class="btn btn-primary" value="Next" />
</div>
</div>
Page 2
#model Student
<body>
<div class="container1">
<form asp-action="Submit" method="post" role="form">
<div class=" form-group row">
<label asp-for="LastName" class="col-md-2 control-label"></label>
<div class="col-md-5">
<input asp-for="LastName" class="form-control" />
</div>
</div>
<div class="form-group row">
<div class="col-md-offset-2 col-md-5">
<input type="submit" class="btn btn-primary" value="Next" />
</div>
</div>
Controller
[HttpPost]
public IActionResult Page2(Reports report)
{
return View(report);
}
[HttpPost]
public IActionResult Submit(Reports report)
{
_reportRepository.CreateReport(report);
return View(report);
}
You need to add a form field for FirstName to the view for Page2, either a hidden field or (assuming you don't want it modified) a read-only input.
<input asp-for="FirstName" type="hidden" />
or
<input asp-for="FirstName" type="text" readonly />
Only values that have some sort of successful control are included in any form submission. This is true for any plain old HTML form, which is (once your view is generated) really what you're dealing with.
If you're coming from a WebForms background, there is no ViewState in any version of the MVC Framework (Full framework or .NET Core), so it's up to you as the developer to persist those values across requests.
I have a problem with Rotativa and Bootstrap. I want to generate a PDF with an inline form but it doesn't display inline. I've made a basic example. I am returning a PartialViewAsPdf and the html is a simple inline form example with bootstrap 4(w3schools). Any ideas?
.cshtml
<form class="form-inline" action="/action_page.php">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox"> Remember me
</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Controller
var actionPdf = new Rotativa.PartialViewAsPdf("File.cshtml", model);
return actionPdf
Expected result:
Actual Result
Rotativa doesn't know about display:flex.Replace this with display:-webkit-box.
I have below code in my .cshtml file,
<div class="input-group col-lg-2 navbar-right" style="margin-top: 7px">
<input type="text" class="form-control" placeholder="Search..." id="searchText" name="searchText" />
<span class="input-group-btn">
<button class="btn btn-default" type="submit" id="btnSearch" onclick="submit()">
<i class="fa fa-search"></i>
</button>
</span>
</div>
When I minimize the window the textbox appears on top of other controls and width of the textbox changes too.
I tried below css but it doesn't work,
<style type="text/css">
.form-control {
width: auto;
position: absolute;
}
</style>
Any ideas what I am doing wrong here?
Have you tried to remove the position: absolute and set width:100%;
Try this:
<div class="form-group">
<div class="col-md-offset-7 col-md-2">
<input type="text" class="form-control" placeholder="Search..." id="searchText" name="searchText" />
</div>
<div class="col-md-2">
<button class="btn btn-default" type="submit" id="btnSearch" onclick="submit()">
<i class="fa fa-search"></i>
</button>
</div>
</div>
Then remove the position:absolute
referring to What is the difference among col-lg-*, col-md-* and col-sm-* in Bootstrap?
your code does not have col-md-* or col-sm-* so properties on minimizing the browser window are simply undefined.
add classes as
<div class="input-group col-lg-2 col-md-4 col-sm-2 navbar-right" style="margin-top: 7px">
Kinda lost in the sauce here...pretty green coming into the ASP.net realm, but have been enjoying my time in it so far.
So let me start from the beginning with this:
Background: I am working on a ASP.net MVC5 application with user login informtion. The user will create an account, recieve messages, etc. The critical component is that there will be a form on the site that allows the user to submit information in a Conditional Logic HTML Form complete with radio buttons, text areas and more. My end goal is to allow the user to fill out and submit the form, therefore submitting it to the MySQL database, sending an email to admin and the user with their selected elements and then populating their responses within their "Account Dashboard" area.
Problem: I am trying to get the user submitted information based on their radio button selection in the HTML Form, which would come in 3 different scenarios:
Web Project
2D Design Project
3D Design Project
So if the user chooses "Web" instead of "Graphic" in the "Project Type" form field, they would be submitting only values related to "Web". The problem I am running into is not being sure on the best way to accomplish this...
Here's the code I've started creating for when the user chooses a Web project for submission to the database:
if (IsPost) && (RadioButton.projectType.Equals(Web))
{
projectType = Request.Form["Web"];
TypeOfWebsite = Request.Form["TypeOfWebsite"];
DeviceExperience = Request.Form["DeviceExperience"];
}
Here is the form values:
<form method="post">
<br />
<div class="row">
<label class="formquestion col-md-3">Project Name:</label>
<input class="col-md-9" type="text" placeholder="Enter project name..." />
</div>
<div class="row">
<label id="ProjectType" for="ProjectType" class="formquestion col-md-3">Project Type: </label>
<span class="col-md-8">
<input id="Web" name="ProjectType" type="radio" value="#Request.Form["Web"] value=" web" />
<label for="Web">Web</label>
<input id="Graphic" name="ProjectType" type="radio" value="Graphic" />
<label for="Graphic">Graphic</label>
</span>
</div>
<div class="hidefield" id="WebProject">
<div class="row">
<label class="formquestion col-md-3">Type Of Website: </label>
<span class="col-md-8">
<input id="WebApplication" name="TypeOfWebsite" type="radio" value="1" />
<label class="Web Application" for="Web Application">Web Application*</label>
<input id="eCommerce" name="TypeOfWebsite" type="radio" />
<label class="choice" for="eCommerce">eCommerce</label>
<input id="SocialNetwork" name="TypeOfWebsite" type="radio" />
<label class="choice" for="SocialNetwork">Social Network</label>
<input id="Forum" name="TypeOfWebsite" type="radio" />
<label class="choice" for="Forum">Forum</label>
<input id="PackageDesign" name="TypeOfWebsite" type="radio" />
<label class="choice" for="PackageDesign">News/Article</label>
<input id="Interactive" name="TypeOfWebsite" type="radio" />
<label class="choice" for="Interactive">Interactive</label>
<input id="InformationalPersonal" name="TypeOfWebsite" type="radio" />
<label class="choice" for="InformationalPersonal">Informational/Personal</label>
<p>*Not exactly sure what a web application is? Well...think TurboTax, Zamzar, Mint, Online Banking Services, MailChimp and Google Docs. </p>
</span>
</div>
<div class="row">
<label class="formquestion col-md-3" for="DeviceExperience">Device Experience: </label>
<span class="col-md-8">
<input id="Desktop" name="DeviceExperience" type="radio" value="1" />
<label for="Desktop">Desktop</label>
<input id="Tablet" name="DeviceExperience" type="radio" />
<label for="Tablet">Tablet</label>
<input id="Mobile" name="DeviceExperience" type="radio" />
<label for="Mobile">Mobile</label>
<input id="Responsive" name="DeviceExperience" type="radio" />
<label for="Responsive">Responsive</label>
</span>
</div>
</div>
<div class="hidefield" id="GraphicDimensions">
<div class="row">
<label class="formquestion col-md-3">Design Dimensions: </label>
<span class="col-md-8">
<input id="2D" name="Dimension" type="radio" value="2D" />
<label class="choice" for="Web">2D</label>
<input id="3D" name="Dimension" type="radio" value="3D" />
<label for="3D">3D</label>
</span>
</div>
</div>
<div class="hidefield" id="2DGraphicProject">
<div class="row">
<label class="formquestion col-md-3">Choose 2D Design: </label>
<span class="col-md-8">
<input id="BusinessCard" name="2DDesign" type="radio" value="1" />
<label class="BusinessCard" for="BusinessCard">Business Card</label>
<input id="Flyer" name="2DDesign" type="radio" />
<label class="choice" for="Flyer">Flyer</label>
<input id="Poster" name="2DDesign" type="radio" />
<label class="choice" for="Poster">Poster</label>
<input id="PrintAd" name="2DDesign" type="radio" />
<label class="choice" for="PrintAd">Print Ad</label>
<input id="PackageDesign" name="2DDesign" type="radio" />
<label class="choice" for="PackageDesign">Package Design (Food/Product/Media)</label>
<input id="Logo" name="Logo" type="radio" />
<label class="choice" for="Logo">Logo</label>
</span>
</div>
</div>
<div class="hidefield" id="hide3DDesignExplaination">
<div class="row">
<label class="formquestion col-md-3" for="3DDesign">Explain this 3D Design project: </label>
<textarea id="3DDesignExplaination" name="3DDesignExplaination" class="textareaform"></textarea>
</div>
</div>
<div class="hidefield" id="ProjectObjective">
<div class="row">
<label class="formquestion col-md-3" for="Objective">Project Objective:</label>
<textarea id="ObjectiveExplaination" name="ObjectiveExplaination" class="textareaform" placeholder="What is this website's primary objective? Sell me on it!"></textarea>
</div>
</div>
<div class="hidefield" id="DesignCopy">
<div class="row">
<label class="formquestion col-md-3" for="DesignCopy">Design Copy </label>
<textarea id="DesignCopy" name="DesignCopy" class="textareaform" placeholder="Any messeging/text/info needed to be included?"></textarea>
</div>
</div>
<div class="hidefield" id="TargetAudience">
<div class="row">
<label class="formquestion col-md-3" for="TargetAudience">Describe Your Target Audience:</label>
<textarea id="TargetAudienceExplaination" name="TargetAudienceExplaination" class="textareaform" placeholder="Who is your target audience? What are their ages? What do they do for a living? Elaborate!"></textarea>
</div>
</div>
<div class="hidefield" id="Keywords">
<div class="row">
<label class="formquestion col-md-3">Keywords To Describe This Project:</label>
<input class="col-md-9" type="text" placeholder="Give me 3 keywords!">
</div>
</div>
<div class="hidefield" id="FirstInteraction">
<div class="row">
<label class="formquestion col-md-3" for="UserFirstInteraction">User First Interaction:</label>
<textarea id="UserFirstInteraction" name="UserFirstInteraction" class="textareaform" placeholder="What Should The User Do First Upon Visiting The Website?"></textarea>
</div>
</div>
<div class="hidefield" id="General2">
<div class="row">
<label class="formquestion col-md-3" for="FavoriteColors">3 Favorite Colors?</label>
<input type="text" class="a-popup" data-color-format="hex" value="GreenYellow">
<input type="text" class="a-popup" data-color-format="hex" value="GreenYellow">
<input type="text" class="a-popup" data-color-format="hex" value="GreenYellow">
<small>Hint: you can type in any CSS color (even named ones, like yellow).</small>
</p>
</div>
<div class="hidefield" id="Necessities">
<div class="row">
<label class="formquestion col-md-3" for="UserFirstInteraction">Necessities:</label>
<textarea id="DesignCopy" name="ProjectReason" class="textareaform" placeholder="What are necessities for this project? Specific graphic/sitefunctionalities?"></textarea>
</div>
</div>
<h5 class="bkgblack center-align col-md-11">Provide URL's of Site/Graphics (whatever is applicable) that design you admire</h5>
<div class="row">
<label class="formquestion col-md-3" for="AdmireURL1">URL #1: </label>
<input id="AdmireURL1" name="AdmireURL1" type="text" maxlength="255" title="" value="http://" />
</div>
<div class="row">
<label class="formquestion col-md-3" for="AdmireURL2">URL #2: </label>
<input id="AdmireURL2" name="AdmireURL2" type="text" maxlength="255" title="" value="http://" />
</div>
<div class="row">
<label class="formquestion col-md-3" for="AdmireURL3">URL #3: </label>
<input id="AdmireURL3" name="AdmireURL3" type="text" maxlength="255" title="" value="http://" />
</div>
<div class="hidefield" id="RivalURL">
<h5 class="bkgblack center-align col-md-11">Provide URL's for "competitor" sites:</h5>
<div class="row">
<label class="formquestion col-md-3" for="RivalURL1">Rival URL #1: </label>
<input id="RivalURL1" name="RivalURL1" type="text" maxlength="255" title="" value="http://" />
</div>
<div class="row">
<label class="formquestion col-md-3" for="RivalURL2">Rival URL #2: </label>
<input id="RivalURL2" name="RivalURL2" type="text" maxlength="255" title="" value="http://" />
</div>
<div class="row">
<label class="formquestion col-md-3" for="RivalURL3">Rival URL #3: </label>
<input id="RivalURL3" name="RivalURL3" type="text" maxlength="255" title="" value="http://" />
</div>
</div>
</div>
<br />
<div class="hidefield" id="ProjectReason">
<div class="row">
<label class="formquestion col-md-3" for="UserFirstInteraction">Project Reason:</label>
<textarea id="DesignCopy" name="ProjectReason" class="textareaform" placeholder="Why does your target audience NEED this project to exist?"></textarea>
</div>
</div>
<div class="row">
<form action="file-upload.php" class="dropzone"></form>
</div>
<button type="submit" name="SubmitForm" class="btn btn-info btn-large">Submit Form</button>
</form>
The various MSDN tutorials I have been looking at to better understand:
http://www.asp.net/web-pages/tutorials/introducing-aspnet-web-pages-2/form-basics
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobutton.aspx
These tutorials haven't made it clear to me on how to create these essential 3 conditional statements for my form:
"If user has chosen Project Type = "Web" and submitted the form, send (insert form variables) to the database"
"If user has chosen Project Type = "Graphic" then Dimension = "2D" and submitted the form, send (insert relative values) to the database"
"If user has chosen Project Type = "Graphic", then Dimension = "3D" and submitted the form, send (insert relative values)" to the database"
Recap:
How do I write the conditional statement to accomplish this?
Should I reconsider the HTML form format I am using in favor of ASP Web Pages?
I have written some JavaScript to show the available form values based upon user selection to follow this schema using the "value" of each field. It works just as intended! Now I'm just trying to connect dots on how to submit this information to the database so I can use it in the user profile. Any thoughts/answers would be greatly welcomed!
That's a complex form. But, for the sake of simplicity I will reduce the number of fields in your form to give you an idea of how things are the MVC way.
I'll start by pointing out that you are not taking the full advantage of MVC. It stands for Model-View-Controller, which is a design pattern. You probably know that stuff, but, I don't see a hint in your code that tells me you are using models in your project, you don't have to...but since you are starting with MVC you should. So, suppose you have the following models...
public class ProjectTypeModel
{
public string Name { get; set; }
}
public class TestModel
{
public IList<ProjectTypeModel> Types { get; set; }
}
Then you're view declares that same model...
#model MvcTest.Models.TestModel
This goes on the top of the view file, the first line of code. The simplified form would look like this...
#using(Html.BeginForm("ProcessTypes","Home")){
<div class="row">
<label class="formquestion col-md-3">Project Type: </label>
<span class="col-md-8">
#foreach (var p in Model.Types)
{
<input id="#("radio_" + p.Name)" type="radio" name="SelectedProjectType" value="#p.Name" />
<label for="#("radio_" + p.Name)">#p.Name</label>
}
</span>
</div>
<input type="submit" name="SubmitForm" class="btn btn-info btn-large" value="Submit Form" />
}
The only thing to note here is that the radio buttons MUST have the same name. The id is not too relevant, just make them unique so you can set the label's for attribute, this way when you click the label the radio button will change its state. The last thing to notice is the form is posting to the "ProcessTypes" action of the Home controller...
and your Home controller's action will look something similar to this...
public ActionResult ProcessTypes(string SelectedProjectType)
{
//processing here...
}
Obviously, the SelectedProjectType will have come with the value of the radio button you selected..."Web" or "Design".
Even though this is a very simplified example you can get an idea of how things work in MVC (and Razor). There's a bit more to cover but I'm sure you will find out by yourself.
Hope it makes sense