Frage

I have a partial view ,which I throw to another view ,In my partial view there is a checkbox which is checked by default I want to change its current (checked/unchecked) option from main view. Here is my partial view code:

<td class="sevenCol" name="sevenCol">
     <input type="checkbox" checked/>
</td>
   

Below shows partial view content:

$("#btnSubmit").click(function () {
    var mobnum = $("#mobNo").val();
    var message = $("#txtMessage").val();
    alert(mobnum);
    $.ajax({
        url: "SmsSendFromOneToOne",
        type: "POST",
        data: { contactList: mobnum, message: message },
        success: function (data) {
            $("#gridGenerate").html(data);
           }
    });
});

Below verifies checkbox is checked or unchecked but it always returns true so how can I fix this?

$("#sendbtn").click(function () {![enter image description here][1]
    var maskId = $("#MASKLIST").val();
    var campaignName = $("#campaignName").val();

    var dataArray = {};
    $(".loadingmessage").show();
    $("#gridGenerate tr").each(function (iii, val) {
        var trId = $(this).attr("id");
        var isChecked = $('td[name=sevenCol]').find('input[type="checkbox"]').is(':checked');
        //alert(isChecked);
        if (isChecked) {
            dataArray[iii] = {              
                'mobile': $(this).find(".secondCol").text(),
                'message': $(this).find(".thirdCol").text(),
                'type': $(this).find(".fifthCol").text()
            };
        }
    });

Controller:

[HttpPost]
public ActionResult SmsSendFromOneToOne(string contactList, string message)
{
    IList<GridPanel> cellInfoForForm1 =    _smsService.GetForm1ForViewing(contactList, message);
                return PartialView("partialGridPanel", cellInfoForForm1);
}

Thanks

War es hilfreich?

Lösung 2

Finally got my answer ,As i am binding a partial view and checkbox exits in it so i have to use jquery .live( events, data, handler(eventObject) )to solve the issue ..

$( selector ).live( events, data, handler );

Again thanks for responding

Andere Tipps

it is a lot simpler if you put the selector directly on the field. try adding a class to your checkbox

<input type="checkbox" class="mobileCheck" checked/>

then in your script you can replace

var isChecked = $('td[name=sevenCol]').find('input[type="checkbox"]').is(':checked');

with

var isChecked = $('.mobileCheck').is(':checked');
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top