Oruam Oruam - 2 months ago 7
ASP.NET (C#) Question

How to pass one (or more) parameter(s) through a button

First of all ASP.NET MVC is very new to me (+- one month).

In my view I've got this code

First block

<label for="from">Data Inicio</label>
<input id="from" name="from" type="text" />
<label for="to">Data Fim</label>
<input id="to" name="to" type="text" />


Second block

<div class="btn-group">
<button type="button" class="btn btn-primary" onclick="listaC006()">Pesquisa Normal</button>
<button type="button" class="btn btn-primary" onclick="flistaC006()">Pesquisa com filtro</button>
</div>


and also

function list() {
$.ajax(
{
type: 'POST',
url: '/Inscricao/_Lista',
dataType: 'html',
cache: false,
async: true,
success: function (data) {
$('#lista').html(data);
}
});
}


in order to fill this "
<div id="lista"></div>
" dynamically.

It's possible to pass the values (datepicker) of "from" and "to" in the onclick event in order to use those values to perform a query?

Answer

To pass parameters on your post add the data argument to your post call:

function list() {
        $.ajax(
        {
            type: 'POST',
            url: '/Inscricao/_Lista',
            dataType: 'html',
            cache: false,
            async: true,
            data: "{'from': '" + $("#from").val() + "', 'to': '" + $("#to").val() + "' }",
            success: function (data) {
                $('#lista').html(data);
            }
        });
    }
Comments