Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
load another view on ajax post

I have a view UserInformation where I am filling few user related information and posting those information to another View "AnotherView" using ajax post.

Now I want to take these inputs in action method "AnotherView" and load the view "AnotherView" with some datamodel.

When I am doing Ajax Post from view UserInformation to action method "AnotherView",It is going to action method "AnotherView",but it is still showing view UserInformation

Ajax call from view UserInformation

$.ajax({
    url: '/somecontroller/AnotherView/',
    data: {
        name: $.trim($('#mgr').val()),
        id: $('#id').val(),
        email: $.trim($('#hdnMgrmail').val())
    },
    cache: false,
    type: "POST",
    dataType: "html",
    success: function (data,
        textStatus, XMLHttpRequest) {
        alert('ok');
    }
});


[HttpPost]
public ActionResult AnotherView(few parametrs that is coming here)
{
      //create model using input params
      return View(with some model);
}
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Since your target Controller Action is returning an ActionResult, then you can expect that it will be returning the rendered HTML (along with any data-binding that occurred).

So the data parameter of your success callback will actually contain this contents, so you can simply use a jQuery selector to determine where you want to output it using the html() function:

success: function (data, textStatus, XMLHttpRequest) {
    // data is your HTML content
    $(...).html(data);
}

It's worth noting that you may want to consider using the PartialView() method if you intend on this returning a small segment of content as opposed to any additional things (like the layout or other related views):

[HttpPost]
public ActionResult AnotherView(...)
{
     return PartialView(...);
}

Update

Since it was mentioned in the comments that it is preferred to have a complete refresh of the page, if that is the case, then you may consider simply submitting a form that posts to the target action and the submission event will handle navigating (and returning the entire action):

<form action='/somecontroller/AnotherView/' method='post'>
    <input id='mgr' name='name' />
    <input id='id' name='id' />
    <input id='hdnMgrmail' name='email' />
    <input type='submit' />
</form>
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda