Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
Window.history.pushState showing the original url before changing to the specified one

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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda