tags:

views:

72

answers:

2

Hi there,

i have some controls on my view like so: " ><%=Html.TextBox("Name")%> " ><%=Html.DropDownList("Intensities")%>

How can i retreive the values of these controls with JQuery?

Something like: var name = $("#name" + id).val(); alert(name);

+1  A: 

well since <%=Html.TextBox("Name")%> make an input type="text" id="Name" name="Name" /> you could just

var name = $("#Name").val(); alert(name); var intensities = $("#Intensities").val(); alert(intensities );

The_Butcher
Note that if you are using "User.Name" syntax, then the id will be rendered as id="User_Name"
Christian Dalager
It's basically a way to control the binding. If you have a Model with a User property on it, this is the best way to bind the User.Name. Both on rendering and on binding in the actionmethod's parameters that you post to.
Christian Dalager
+1  A: 

In order to reference the textbox the way you propose you will need to give the textbox a custom id like this, supposing you're iterating over a collection of users:

<%foreach(var user in Model.UserCollection){%>
    <%= Html.TextBox("Name",user.Name,new{id="name"+user.Id})%>
<%}%>
Christian Dalager