Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference a control's ID created with TextBoxFor()

I am loving ASP.NET MVC, keeping up with the releases/docs can sometimes be tricky, so maybe I'm just not getting something... I want to use a TextBoxFor(), and working with LabelFor() etc. is fine, all the magic happens for me.

But if I create...

 <%=Html.TextBoxFor(x => x.LastName) %>

And wanted to do something nice with jQuery, how would I get the ID of the control that was created? I could add a CSS class and use that to attach my jQuery, but for something I am doing I would like the ID... so I could do something like:

 $('#LastName').(...)

I know I could work it out in this case, and hack it in manually, but is there a neater way?

like image 250
Colin Asquith Avatar asked Mar 24 '10 17:03

Colin Asquith


1 Answers

I think you can do something like:

<%=Html.TextBoxFor(x => x.LastName, new { id = "LastName" })%>

Overloads of TextBoxFor

like image 96
bruno conde Avatar answered Nov 11 '22 13:11

bruno conde