Madhukar Krishna

Madhukar Krishna

  • 652
  • 1.4k
  • 281.8k

How to create simple list of string in view with data from textbox wit

Dec 22 2021 8:38 AM

I want to create a simple list of string in view, submitted from textbox, using submit button, without using model, using razor. I want that on every submit a new string in the list is created. I am trying the following code but it just creates one string in the list :

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<form action="" method="post">
    <p style="float:left;">Message: </p>
    <input type="text" name="message" style="float:left;" />
    <br /><br />
    <input type="submit" value="submit" />
</form>

@{ var message = "";
        if (IsPost)
        {
            message = Request["message"];
            <p> @message </p><br />

        }
    }

 


Answers (3)