Changing model value by Jquery and Asp.Net MVC?

Asked

Viewed 338 times

0

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

To define these values I am trying to use Jquery and change the model value when doing Submit, checking which button was clicked to change the value of status, but I’m not getting it.

How can I do that ?

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);            
        });

1 answer

-1

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');            
        });
  • does not work, from the following error: Uncaught ReferenceError: Invalid left-hand side in assignment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.