Joe G Joe G - 1 year ago 176
HTML Question

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.


string message = "";
string fName;

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

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


<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" />

Answer Source

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/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download