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

105
Visualizações
Window.history.pushState shows original url with a flash before changing to what has been defined

My project uses ASP.NET MVC. I have a form in my cshtml file on which if I do submit, it calls a specific action in the controller. I do not want the action name to appear in the url. So I used window.history.pushState to change the url to the default one. But actually, when I hit the submit button on the form, the actual url with the action name shows up in a flash in the address bar before shifting to the specified one. How do I solve this issue please? Thank you :)

Cshtml

  @using (Html.BeginForm("Step2", 
  "Restaurants",FormMethod.Post))

 {
  @Html.AntiForgeryToken()
  <div class="container">
  <div class="form-horizontal">
            <div class="input- 
   group">
             @Html.TextBoxFor(m 
   => m.FoodName, new { 
      @class = "form-control})
  </div>

 <button type="submit" class="btn 
  nextBtn">Next </button>
  </div>   
 </div>
}

Restaurants Controller

Restaurant res = new 
RestaurantDetails();

public ActionResult Index()
 {
    ViewBag.Step = 1;
    ViewBag.Title = "MAIN 
    COURSE";
    mymodel.Restaurant = 
   RestaurantList.Where(x => x.Id 
    == 
    “1234”.FirstOrDefault();
  return View(res);
  }

[HttpPost] [ValidateAntiForgeryToken] public ActionResult Step2(Food foodItem) { ViewBag.Step = 2; ViewBag.Title = "MAIN COURSE"; }

Index.cshtml

@if (ViewBag.Step == 1) {

@Html.Partial("~/Views/Menu/_Starters.cshtml") }

@if (ViewBag.Step == 2)
{     
   @Html.Partial("~/Views/Menu/P
   artials/_MainCourse.cshtml", Model)
 }
about 4 years ago · Juan Pablo Isaza
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