I’ve written a code snippet creates HTML form via C#. But I want the form’s fields to be bound class’s field after the form is submitted. How can I do that and check the result(if the class’s fields are filled)? Moreover, I don’t know how to test the code via Postman
or Fiddle
. Could you exemplify? For example, when the form is filled via a browser, I don’t know how to see the result forwarded to sent
.
HTML form,
<form action="sent” method="POST"<br>
<label for="firstName">First Name Label:</label>
<input type="text" title="testTitle" name="firstName" placeholder="First Name" ><br>
<label for="lastName">Last Name Label:</label>
<input type="text" name="lastName" placeholder="Last Name" ><br>
<input type="submit" name = "noname">
</form>
Nancy,
Get("/form", parameters =>
{
// codes to construct the above HTML code
return Response.AsText(form.ToString(), "text/html");
}
// Received form information (fields)
Post("/sent”, _ =>
{
testClass receivedData = this.Bind<testClass>();
return new
{
success = true,
message = $"Record recieved First Name = {receivedData.Name}",
message2 = $"Record recieved Last Name = {receivedData.SurName}"
};
});
testClass,
public class testClass
{
public string Name { get; set; }
public string SurName { get; set; }
}