Update

Asked

Viewed 728 times

0

How do I update a partialview (Asp .net) after I select some parent information, for example:

I have a list of bills and a partialview next door to show you the items in that note. When selecting one of the bills my partialview should fetch the items according to the selected note, how to do?

  • 1

    Using ajax. You must implement some javascript function that monitors the changes and searches the server for the necessary information.

  • You have some example Richard Dias?

  • 1

    I believe this may give you an idea of what to do: http://stackoverflow.com/questions/19392212/how-to-use-jquery-or-ajax-to-update-razor-partial-view-in-c-asp-net-fora-mvc-p

1 answer

2


Implement a function that uses ajax to communicate with a controller (DetalheNotaFiscalController, for example):

function DetalharNotaFiscal(idNota) {
    $.post("/DetalheNotaFiscal/Detalhar", { id: idNota }).done(function (retorno) {
        $("#detalhe_nf").html(retorno); //id da div com a partial, recebendo o retorno da controller
    }).error(function (xhr, ajaxOptions, errorThrown) {
        alert("Erro Interno. Favor contatar o administrador.");
    });
}

In the controller:

[HttpPost]
public ActionResult Detalhar(string id)
{
    //TODO: Recuperação da nota através do id
    var model = TODO; //model da partial view

    return PartialView("Index", model);
}

Browser other questions tagged

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