使用AJAX在MVC4移动网站(Razor View Engine)中发布URL问题

时间:2022-09-12 15:13:17

I am developing a mobile website in MVC4 (using Razor view Engine). The issue I am facing is that When I navigate to different View using RedirectToAction() method, the new view is served but the URL remains the same in the browser.

我正在开发MVC4中的移动网站(使用Razor视图引擎)。我面临的问题是,当我使用RedirectToAction()方法导航到不同的View时,会提供新视图,但URL在浏览器中保持不变。

I searched about it and found that If I disable the AJAX on my page (by setting attribute [data-ajax=false]) then It start working fine(i.e. correct URL is displayed). But Ajax stops working.

我搜索了它,发现如果我在我的页面上禁用AJAX(通过设置属性[data-ajax = false]),那么它开始工作正常(即显示正确的URL)。但是Ajax停止了工作。

But my problem is that I can not disable AJAX for mobile website & I need to display correct URL for each page.

但我的问题是,我无法禁用移动网站的AJAX,我需要为每个页面显示正确的URL。

EDIT:

[HttpPost]
public ActionResult Search(string btnSelection)
{
  //Some code here... 
  //Then redirect to another View using following command:
  return RedirectToAction("SelectTask", "Task");
}

But to achieve proper URL display in MVC4 mobile, I have to set following attribute in View:

但要在MVC4 mobile中实现正确的URL显示,我必须在View中设置以下属性:

@using (Html.BeginForm("Search", "Task", FormMethod.Post, new { data_ajax = false }))

But this stops the AJAX. Any ideas how to fix this using AJAX?

但这会阻止AJAX。有任何想法如何使用AJAX解决这个问题?

Please help if you can asap.

请尽快帮忙。

Thanks.

1 个解决方案

#1


0  

Ajax is not for navigating. You must submit form if you have data to save or use a link (e.g. @Html.ActionLink("Home", "Index", "Home")) to redirect to the other view.

Ajax不适用于导航。如果您有要保存或使用链接的数据(例如@ Html.ActionLink(“Home”,“Index”,“Home”))以重定向到另一个视图,则必须提交表单。

#1


0  

Ajax is not for navigating. You must submit form if you have data to save or use a link (e.g. @Html.ActionLink("Home", "Index", "Home")) to redirect to the other view.

Ajax不适用于导航。如果您有要保存或使用链接的数据(例如@ Html.ActionLink(“Home”,“Index”,“Home”))以重定向到另一个视图,则必须提交表单。