1

I have an input in ASP.NET form. I did not use ASP.NET controls, but the adjective runat="server" was used. Like this:

<input id="cmbIOType" name="cmbIOType" runat="server" list="listcmbIOType" autocomplete="off" data-id="564" value="111" />

I'm using strig valcmbIOType = cmbIOType.value; to get the input value. I also need to data-id the input.
I used string idcmbIOType = cmbIOType.Attributes["data-id"] but returned NULL. Meanwhile, the data-id is made by Jquery.

Please help.

3
  • 1
    What does this have to do with MVC? Commented Mar 3, 2015 at 5:20
  • 1
    Post code where you data-id is made by jquery. Commented Mar 3, 2015 at 6:20
  • No other attributes than name and value are posted. Take a different approach, for example using AJAX. Commented Mar 3, 2015 at 10:28

1 Answer 1

1

i used this:

<input id="cmbLoc" name="cmbLoc" runat="server" list="listcmbLoc" autocomplete="off" />
<datalist id="listcmbLoc">
       <option data-id="15" value="CPF"></option>
       <option data-id="18" value="HOLD"></option>
       <option data-id="19" value="CCR"></option>
 </datalist>
<div style="display: none"><input id="cmbLoc_ID" type="text" name="cmbLoc_ID" runat="server"/></div>
<script type="text/javascript">
    $(document).ready(function () {
          $("#cmbLoc").change(function () {
$("#MainContent_cmbLoc_ID").val($('#listcmbLoc').find('option[value="' + $(this).val() + '"]').data('id'));
          });
    });
</script>

And enter cmbLoc_ID.value in the code behind it to get data-id.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.