Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you access a model attribute in jquery?

I'm adding an object to my ModelAndView in spring and forwarding to my jsp view. I need to access that object in my jquery. Is this possible without first putting the value in a hidden field? How is it done?

like image 723
coder Avatar asked Feb 16 '11 19:02

coder


People also ask

What are model attributes?

Model attributes are the data representations used internally by the model. Data attributes and model attributes can be the same. For example, a column called SIZE , with values S , M , and L , are attributes used by an algorithm to build a model.

How does model attribute work?

ModelAttribute can be applied to both methods as well as method-parameters. It accepts an optional "value", which indicates the name of the attribute. If no value is supplied to the annotation, then the value would default to the return type name in case of methods and parameter type name in case of method-parameters.

What is model attribute in controller?

@ModelAttribute is an annotation that binds a method parameter or method return value to a named model attribute, and then exposes it to a web view. In this tutorial, we'll demonstrate the usability and functionality of this annotation through a common concept, a form submitted from a company's employee.

What is model add attribute?

1) addAttributeIt adds the specified attribute under the supplied name. Model addAttribute(String attributeName, @Nullable Object attributeValue) attributeName - the name of the model attribute - can never be null attributeValue - the model attribute value - can be null.


1 Answers

<script type="text/javascript">
   var modelAttributeValue = '${modelAttribute}';
</script>

This will resolve the model attribute added by model.addAttribute("modelAttribute", value)

like image 139
Bozho Avatar answered Oct 10 '22 23:10

Bozho