Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!