简体   繁体   中英

Passing variable from view to the controller without query string

I'm fairly sure I'm missing something very practical but I'm floundering at finding it online.

How do you pass information from the view to the controller without using URL items (query strings, /variable/ etc?

The easiest scenario I can think that surely must have an example is a simple set of login credentials handed to a controller. Naturally you wouldn't want the username / password to be viewable in the URL.

You can POST data to the controller, so that it doesn't appear in the URL. See this blog post for details.

The basic steps are:

  1. Create a form on the view and name the fields in which you are interested.
  2. Create an action on the controller whose parameters match those names.
  3. Add the [AcceptVerbs(HttpVerbs.Post)] attribute to the action.

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