I have the following cshtml form:

@model IEnumerable<HMSDataAccessLayer.usp_FetchTestParameters_Result>

@{
Layout = null;
<style type="text/css">
    .Grid {
        width: 100%;
    }
</style>
}
@using (Html.BeginForm("UpdateLabTechniciansResults", "LabTech"))
{
<div style="font-size:large;font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;text-align:center;text-decoration:underline">Test Results: </div>
<div>

    <link href="~/Content/Grid.css" rel="stylesheet" />


    <div style="width:100%;">
        @if (true)
        {
            {
                WebGrid grid = new WebGrid(Model);

                @grid.GetHtml(
     tableStyle: "Grid",
     fillEmptyRows: false,
     headerStyle: "head",
     alternatingRowStyle: "alternate",
     rowStyle: "gvRow",
     footerStyle: "gvFooter",


     mode: WebGridPagerModes.All,
     firstText: "<< First",
     previousText: "< Prev",
     nextText: "Next >",
     lastText: "Last >>",
     columns: new[] {
                    grid.Column("ParameterDescription", "Parameter", canSort: false, style: "col"),
                   grid.Column(columnName: "Value",canSort: false, header: "Value", format:@<text><input type="text" id="TestParameter[@item.ParameterID]" onchange="fn()" required /></text>),

    })

            }
        }
        else
        {
            <p style="text-emphasis: sesame; color: red; text-align: center; outline-color: #09826b; outline-style:solid; "><b>No Data Found</b></p>
        }



    </div>


    <div style="font-size:small;font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;text-align:center">
        <b> Approved: </b> <input type="radio" name="Status" value="1" checked />Approved
        <input type="radio" name="Status" value="0" />Rejected
        <br />
        <br />


        <b>Remarks: </b><textarea rows="4" cols="50" id="Remarks" name="Remarks" />

        <input type='hidden' id='test19' value=''>
        <input type='hidden' id='test20' value=''>
        <input type='hidden' id='test21' value=''>
        <input type='hidden' id='test22' value=''>


    </div>
    <div>
        <br />
        <input type="submit" onclick="Add()" value="Submit" style="background:#09826b ; color:white" class="btn btn-default" />
        <input type="reset" style="background:#09826b ; color:white" class="btn btn-default" />
    </div>
</div>
}

I have method which gets all these form values. I'm getting the values that are outside the grid correctly in that method but the values inside the grid are receieved as null. I tried adding jquery to add those values to the hidden text fields onchange, but the jquery is not getting hit at all.

How to pass the web-grid text-fields' values to the method (given below)?

public ActionResult UpdateLabTechniciansResults(FormCollection frm)
    {
    }

jquery:

$(function () {
    $('#TestParameter[19]').change(function () {
        var x = $(this).val();
        $('#test19').val(x);
    });
});


$(function () {
    $('#TestParameter[20]').change(function () {
        var x = $(this).val();
        $('#test20').val(x);
    });
});

$(function () {
    $('#TestParameter[21]').change(function () {
        var x = $(this).val();
        $('#test21').val(x);
        alert(x);
    });
});

$(function () {
    $('#TestParameter[22]').change(function () {
        var x = $(this).val();
        $('#test22').val(x);
    });
});

Related posts

Recent Viewed