serialize an array and pass as parameter to model

Asked

Viewed 44 times

0

My Action:

 public JsonResult SalvarCadastro(ListaModelView model)
 {    }

My Model:

    public string Assunto { get; set; }
    public string Mensagem { get; set; }
    public List<ContatosEmailModelView> Lista { get; set; }

My Js: Form input is Subject and Message. Lists this out of the form in a Table:

var dados = $("#form-envio-manual-cadastro").serialize();
$("#lista tr").each(function () {
            var linha = [];
            var tableData = $(this).find('td');
            if (tableData.length > 0) {
                tableData.each(function () { linha.push($(this).text()); });
                lista.push({ Email: linha[0], Contato: linha[1] });
            }
        });
 var list = '';
        $.each(lista, function (key, value) {
            list += encodeURIComponent($.param(lista[key])) + ';';
        });

        dados += '&Lista={' + list + '}';

When calling the action by passing data as parameter, it is not filling the List property, only subject and email. How do I fill a List property?

  • The result given is: "Title=&Subject=&Message=&Newmail=&Name=&Registration=&List={Email%3Dtest%2540email.com.br%26Contact%3DJuracil%2Bereira;Email%3Dmaria%2540email.com%26Contact%3DMaria%2BTeixeira;}"

  • but in this result the list is filled with the emails and names

  • But in the action the Model List property is Count = 0

  • If passing as string works?

  • I don’t understand Wees. It passes string like?

  • in the model you are passing as list, forehead pass as string

Show 1 more comment
No answers

Browser other questions tagged

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