PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 9, 2022

[FIXED] how do I display data to a text area in html from any sort of input aka text box or database in asp.net core ( runat doesnt work or pop up)

 November 09, 2022     asp.net, asp.net-core, c#, html, visual-studio     No comments   

Issue

i can't find anything that tells me how to display data to a text area from a database or textbox


Solution

how to display data to a text area from a database

You can refer to the below demo.

Controller:

 public IActionResult Index()
        {
            TextInputModel model = new TextInputModel();
            model.list = new List<string> { "answer1", "answer2", "answer3" };
            model.Name = "aa";//you can get your data from batabase too...
            return View(model);
        }

TextInputModel:

public class TextInputModel
    {
        public List<string> list { get; set; }
        public string Name { get; set; }    
    }

Index view:

@model TextInputModel 


<div class="form-group">
            <label class="control-label">List</label>
            <textarea name="list" class="form-control" style="text-align:right">@string.Join("\n ", Model.list)</textarea>
        </div>
        
<div class="form-group">
            <label class="control-label">Name</label>
            <textarea name="Name" class="form-control" style="text-align:right">@Model.Name</textarea>
        </div>

result: enter image description here

I have text boxes and a submit button when the button is pressed it must display to the text area

I create a view to show text box and a view display data to a text area.

Controller:

        public IActionResult Show()
        {
            return View();
        }
        [HttpPost]
        public IActionResult Show(string Name)
        {           
            ViewBag.Name = Name;      
            return View("ShowText");
        }

Show view:

<form method="post"  asp-action="Show">
    <input type="text"  name="Name"/>
    <input type="submit" value="Submit"/>
</form>

ShowText view:

<textarea name="Name" class="form-control" style="text-align:right">@ViewBag.Name</textarea>

result: enter image description here



Answered By - Qing Guo
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing