Answer the question
In order to leave comments, you need to log in
How to iterate over a collection and assign values to a variable?
I need to make a web shell. I did almost everything, only the following remains: Remember the history of entered commands in the database on the server, restore the history of those entered when entering the page, scroll through the history with the up and down keys (as, for example, in bash or PowerShell).
I have a database where the commands that I entered in the field are already added, but I can't implement viewing commands using the keys.
I have html code:
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Bash command" aria-label="Bash command"
aria-describedby="basic-addon2" <b>@bind="_bashCommand"</b> <b>@onkeydown="OnKeyDown"</b>>
<div class="input-group-append">
<button class="btn btn-outline-secondary" @onclick="Method" type="button">Send</button>
</div>
</div>
private IEnumerable<BashData> _allCommands = new List<BashData>();
private void GetAllBashCommands()
{
_allCommands = repository.GetAllCommands();
}
private void OnKeyDown(KeyboardEventArgs args)
{
switch (args.Key)
{
case "ArrowUp":
_bashCommand = ;
break;
case "ArrowDown":
_bashCommand = ;
break;
}
}
Answer the question
In order to leave comments, you need to log in
On the client side, after pressing the keys, you need to initiate an Ajax request to the server, then catch the response from the server, which command to put in the field.
But every time it's kind of crooked to follow the commands to the server. I would pass the last 10 commands along with the page, and climb the server only if I need to get into an earlier history.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question