0

I am new in ASP.Net MVC and JQuery.

I want to get row detail including selected dropdownlist value placed in one column.I want to store value in one object like customer = {customerId :'',customerName:''}

so How can I do this using JQuery.

here is my table structure.

<table style="table-layout: fixed;" class="data-display-table" id="tblFleet">           
            <tbody>
                @foreach (var item in Model)
                {
                    <tr>
                        <td>
                            <input type="checkbox" id="[email protected]"  />
                        </td>

                        <td>
                            @item.CustomerId
                        </td>
                        <td>
                            @item.CustomerName
                        </td>
                        <td>
                            @item.ContactNo
                        </td>                        
                        <td>
                            @{string ddlId = "ddl" + item.CustomerId}

                            @Html.DropDownList(ddlId, (IEnumerable<SelectListItem>)ViewBag.MessageTemplateList, new { @style = "width:140px" })
                        </td>
                    </tr>
                }
            </tbody>
        </table>

3 Answers 3

1

I'm sure if you use @Html.CheckBoxFor, it will automatically understand whether or not the checkbox is ticked or not.

For instance if you use a with the input tags (input type="submit")

Which posts back to the controller, as long as you pass in the model (which is what I assume you're doing since you would use CheckBoxFor), ASP should understand if its checked

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

Comments

0

Try this : bind change event for checkbox and then find its parent tr and then find select box inside parent tr.

$(function(){
  $('input[type=checkbox]').change(function(){
     if($(this).is(':checked')
     {
       var parentTR = $(this).closest('tr');
       var selectBox = $(parentTR).find('select');
       var selectBoxValue = $(selectBox).val();
       alert(selectBoxValue);
     }
  });
});

Note - I am reading select box value when checkbox is selected, you can remove if condition if this is not your requirement.

Comments

0
$(document).ready(function(){
  $('input[type="checkbox"]').change(function(){
    if($(this).is(':checked'))
    {
      var customerid =  $(this).closest('tr').find('td').eq(1).text();
      var drop =  $(this).closest('tr').find('td').eq(4).find('select option:selected').val();
    }
  });
});

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.