为什么 URL 更改为我已将数据发布到的操作名称?

Why does the URL changes to the action name to which I have posted the data?

我有这个控制器

  [HttpPost]
        //[Bind("")]
        public ActionResult AddStories(Stories st, HttpPostedFileBase files)
        {
            try
            {
                if (files != null)
                {
                    string filePath = Path.Combine(Server.MapPath("~/UploadedFiles/"), Path.GetFileName(files.FileName));
                    files.SaveAs(filePath);
                }

                st.Image = Path.GetFileName(files.FileName);
                listofStories.Clear();
                listofStories = bo.GetAllImages();

                if (bo.insertImages(st))
                {
                    ViewBag.Data = "Added";

                    ViewBag.Grid = listofStories;

                    ViewBag.Style = "display:none";
                    ViewBag.StyleAdd = "";
                }
                else
                {

                }
            }
            catch (Exception ex)
            {
                ViewBag.Data = ex.Message;
            }


            return View("GetStories", st);
        } 

为此,我有一个嵌入在主视图中的绑定局部视图,GetStories

当我向它提交数据时,URL 更改为 /Stories/AddStories,但我希望它在发布后成为 parent 的视图,例如 /Stories/GetStories将数据添加到 AddStories。

我尝试了几种方法,但没有任何效果。

我很天真

当您 post 时,您的浏览器将导航至 post url。只有两种方法可以让它在之后显示不同的 url:

  • 而不是return查看视图好像他们点击了那个url,return一个重定向 到首选 url (因此浏览器执行 post 后跟 get)
  • 使用客户端欺骗来更改显示 url - 例如 replaceState (取决于浏览器)

例如,当您 post 编辑这个问题时,您的浏览器执行 POST 到 /questions/ask/submit,并且该路由后面的 C# 的最后一行是重定向到 /questions/46975286/why-does-the-url-changes-to-the-action-name-to-which-i-have-posted-the-data