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.