【问题标题】:MVC 4 Mobile Template Redirect To Action fails after post发布后 MVC 4 移动模板重定向到操作失败
【发布时间】:2012-06-18 07:25:06
【问题描述】:

我在一个项目中使用 MVC 4.0 移动模板,但在使用默认脚手架/模板时遇到了一个奇怪的问题。 我创建了一个简单的模型:

public class Person
{
    public int Id { get; set; }
    [Required]
    public string Name { get; set; }
}

然后我创建了一个带有索引操作和创建操作的简单控制器:

public ActionResult Index()
    {
        List<Person> persons = new List<Person>();
        return View(persons);
    }

public ActionResult Create()
    {
        Person p = new Person();
        return View(p);
    }

    //
    // POST: /Person/Create

    [HttpPost]
    public ActionResult Create(Person p)
    {
        try
        {
            // TODO: Add insert logic here
            //empty

            //return Redirect("/Person/Index");
            return RedirectToAction("Index", "Person", null);
        }
        catch
        {
            return View();
        }
    }

为两个动作生成了视图:对于索引,我生成了一个列表视图,对于创建,我生成了一个创建视图。现在的问题是,在我创建一个新产品后,它应该重定向到索引视图,它以一种奇怪的方式执行,但 url 仍然是 /Person/Create,然后当我单击索引视图上的“新建”链接时,什么也没有发生。 (在生成时创建新链接:@Html.ActionLink("Create New", "Create"))

我认为这是一个错误,但我还没有在网上找到任何东西.. 关于如何完成这项工作的任何建议?

谢谢。

【问题讨论】:

    标签: jquery c#-4.0 jquery-mobile asp.net-mvc-4 beta


    【解决方案1】:

    有一个解决方法:jQuery Mobile/MVC: Getting the browser URL to change with RedirectToAction

    此外,页面没有刷新(我使用了 IE),所以我必须遵循这个答案才能在 RedirectToAction 之后在 IE 上刷新页面:How to stop MVC caching the results of invoking an action method?

    【讨论】:

      猜你喜欢
      • 2019-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-01
      • 1970-01-01
      相关资源
      最近更新 更多