Update all View data via Ajax

Asked

Viewed 136 times

3

I need to update all my data View, i call this function to update, passing the company parameter:

function CarregaCaixa() {
var Empresa = $("#EmpresaFiltroId").val();

var url = "/Caixa/CarregaCaixa";
$.ajax({
    url: url
    , type: "POST"
    , data: { empresaId: Empresa }
    , datatype: "html"
    , success: function (data) {
        $("#model").html(data.model);
    }
});

}

And in the controller I return like this:

        var model = new CaixaViewModel();
        model.EmpresaList = new SelectList(empresa, "Id", "Value");
        model.ValorSaida = ValorSaida.ToString("C2");
        model.ValorEntrada = ValorEntrada.ToString("C2");
        model.EmpresaFiltro = new SelectList(empresa, "Id", "Value");
        model.EmpresaFiltroId = empresaId;
        model.CaixaList = union;
        return Json(new { model });

How can I return all the data at once, I’m updating my data View, has some way without needing to pass field by field.

  • Mariana, have you seen this post? -> How to send 2 objects from Controller to View in C# ASP.Net MVC? - https://answall.com/questions/91021/comor-enviar-2-objects-do-controller-para-a-view-no-c-asp-net-mvc

  • @Fabioin I did not want to send one or other objects, I wanted to update the whole View. I will take a look at the post. The form of the post, is by ViewData or ViewBag. I wanted to see if you had something that would update all the data.

  • I use the viewmodel, p update the View, works in the load, only I need the user to pass a parameter, then filter the data and update again, with the filter, as the parameter provided.

  • You need to return to View for controller the technique would be with PartialView and update this View by the controller ... I think that’s what you need?

  • @Virgilionovic I didn’t want to use PartialView, wanted to update everything in a single page, because for PartialView I would need to make another page to update.

  • Remembering that I use core

  • I would make a party views, but if you don’t want to work with angular reactive framework, Reactjs or Vue

Show 2 more comments
No answers

Browser other questions tagged

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