Get input ID generated by asp.net

I have an input field generated by

<%= Html.TextBoxFor(model => model.Card.ExpiryDate) %> 

which leads to html

 <input id="Card_Expiry_Date" name="Card.ExpiryDate" type="text" value=""> 

I also have a javascript function

 <script type="text/javascript"> $().ready(function() { $('#Card_Expiry_Date').datepicker({ dateFormat: 'yy-mm-dd' }); </script> 

How can I get the input identifier to be generated so that I don't have to hardcode the identifier in my function?

+4
source share
3 answers

Thank you Ahmad for the comment, this is what I was looking for!

Client Identifier for the Property (ASP.Net MVC)

+1
source

You can specify an ID when creating a text field:

 <%= Html.TextBoxFor(model => model.Card.ExpiryDate, new { id="Card_ExpiryDate" }) %> 

Then this will certainly work:

  $('#Card_ExpiryDate')... 
+1
source

I'm not sure about MVC, but in Forms you enter the textbox id in html. Something similar to:

 $get('<%= TextBox1.ClientID %>') 

Link with explanation here .

0
source