The Controller obtains the Field value. The controller obtains the Field value.

Source: Internet
Author: User

The Controller obtains the Field value. The controller obtains the Field value.

In ASP. net mvc, there are many methods to POST Data to the Controller. But what if we want to get the Feild value in the controller? How to get it?
You can notice that there is a FormCollection class. It helps us solve this problem.


Here is a simple example. In the ASP. net mvc application, create a SepController Controller under the Controllers directory. Now the exercises we did in July and July are all done under this controller.


Then, under the Views directory, the corresponding controller creates the PostDataToControl. cshtml view, in the View:



There is a text box and a submit button, which is used to post data to the Controller. OK, we also need to create another Action in the controller:


See the results:



How to obtain the form value in the controller?

@ RequestMapping (value = "/login", method = RequestMethod. GET) public ModelAndView myMethod (HttpServletRequest request, HttpServletResponse response, // @ RequestParam ("username") String username, @ RequestParam ("password") String passwordString username, String password, // ModelMap modelMap) throws Exception {username = new String (username. getBytes ("iso8859-1"), "UTF-8"); // encoding problem (a bunch of servers are iso) System. out. println (username + ":" + password); modelMap. put ("loginUser", username); modelMap. put ("msg", "I'm in session"); return new ModelAndView ("/view/hello", modelMap );}
Here is a method. springMVC parameters can be directly stored in the parameter list of the method. If it is an object attribute, you can also directly use an object such as (User user ,...)

The frontend of the method is as follows:
<Form action = "login">
Username:
<Input name = "username"/>
<Br>
Password:
<Input name = "password" type = "password"/>
<Br>
<Input type = "submit" value = "login"/>
</Form>


How to obtain the HiddenField value in repater

Of course, the Repeater is composed of N repeateritems (the popular point is N rows), each line has HiddenField1, and the landlord intends to Find that one?

First, we need to look for the events of the control to be located, but it must be the HiddenField1 of a line.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.