Changing model value by JQuery and Asp.Net MVC?

0

I have a model where I have the attribute status , this attribute is a int that I define values. In my form I have 2 buttons: gravar e publicar and gravar , each of these buttons would be a status value, in which case gravar e publicar has value 1 and gravar value 0.

To set these values I'm trying to use JQuery and change the value of the model when submitting, checking which button was clicked to change the value of status , but I'm not getting it.

How can I do this?

I'm trying like this.

html

<input type="submit" class="btn btn-success" value="Gravar e Publicar" id="gravarPublicar"/>
<input type="submit" class="btn btn-success" value="Gravar" id="gravar" />

jquery

$(document).ready(function () {
    $('#addPropriedade').submit(function () {
        //var dados = $(this).serialize();
        var dados = new FormData($('#addPropriedade').get(0));

        $('#gravarPublicar').click(function () {
            dados.status = 1;
            console.log(dados.status);            
        });
        $('#gravar').click(function () {
            dados.status = 0;
            console.log(dados.status);            
        });
    
asked by anonymous 26.05.2017 / 19:32

1 answer

0

You can use:

$(document).ready(function () {
    $('#addPropriedade').submit(function () {
        //var dados = $(this).serialize();


        $('#gravarPublicar').click(function () {
           '@Model.status' = 1;
            console.log('@Model.status');            
        });
        $('#gravar').click(function () {
              '@Model.status' = 0;
            console.log('@Model.status');            
        });
    
26.05.2017 / 19:36