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)
}