简体   繁体   中英

Prompt for user input on website using C# (not console application)

Usually if we make a Console application in Asp.net, then we can prompt for user input, and make the system wait until the user has provided input. For example by using:

Console.ReadLine();

But as mentioned, this is (from my experience) used in a console application. My problem is that I am creating a website. And in that website, at some point, I am going to need the user to give some keyboard input. Is this possible in some way using C#?, when I'm not creating a console application? The only thing I have found out so far, is that I can probably use JS. It has the prompt("...") function. But doing it this way, I'll then have to use AJAX or similar, to pass the input to the server.

I have a link looking like this:

@Html.ActionLink("Attach card", "AttachCard", new { cardID = ..., Model.MemberID })

This is when the user should be prompted to provide input.

I am using ASP.net MVC.

Ps. If it is not possible achieving what I want using C#, is the solution that I mention, using JS promt(...) function a sound solution?

Because web applications are stateless, they tend to be designed differently to desktop applications.

In the case you are referring to it is better to have a form that has input s for the values you require.

This way, you can also validate the client-side data to ensure that only legal values are submitted (also validate on the server too).

When the user has completed the form ( ID and string values) they can click a button to submit the form to the server.

On the server you can process the data using C# , then return a page/view to notify the user of the result etc.

Note: It is not secure to 'prompt' the user for some values that you directly store in a database - always validate (especially the string data).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM