简体   繁体   中英

CSHTML displaying user inputs

My web assignment has asked me to create a dating site login page and display the information, i have completed the HTML to a point and am now beginning with the C#. I have began this but have come to a standstill as I dont know what is going wrong to display the information.

My question is: How do I get the "fName" to display itself in the "message" as when I submit it, the text comes up but there is no name when I type it into the textbox and submit it.

C#

@{
string message = "";
string fName;

fName = Request.Form["fName"];
string daySelect = Request.Form["submit"];

message = String.Format("Your first name is: {0}", Request.Form["fName"]);
}

HTML

<form method="post">
<label for="fName"></label>
First Name: <input type="text" name="fName" id="fName" 
@(Request.Form["fName"]) /> <br/>

<br/><br/><input type="button" value="submit" />
<p>@message</p>

I recommend to look into ASP.NET MVC and how are models passed from controller to their views. This makes things you are doing here a lot of easier and less error prone. There are several tutorials out there.

Just looking at your HTML code a missing value attribute in the input field may be the cause. Please try

First Name: <input type="text" name="fName" id="fName" value="@(Request.Form["fName"])" /> <br/>

I found the problem.

Here is the submit that I have in:

<br/><br/><input type="button" value="submit" />

As you can see the type is button, for this code it should be of type "submit", tiny error in lots of code. Thanks to rboe for the assistance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM