MVC中的RediretAction导致" Web服务器配置为不列出该目录的内容"

时间:2014-04-04 16:48:48

标签: asp.net-mvc asp.net-mvc-4

我有一个像这样的 contentController

 public class ContentController : Controller
    {
        public ActionResult Index()
    {
        var model = obj.GetContentlist();
        return View(model);
    }
        [HttpPost]
        public ActionResult Create(Content content)
        {
            obj.AddNewContent(content);
            obj.Save();
            return RedirectToAction("Index","content");
        }
}

你可以看到包含创建动作。但是在最后一行,当它将被执行时 RedirectToAction("索引","内容"); 我收到了这个错误:

    HTTP Error 403.14 - Forbidden
    The Web server is configured to not list the contents of this directory.

    Most likely causes:

    A default document is not configured for the requested URL, and directory browsing is not enabled on the server.

1 个答案:

答案 0 :(得分:1)

默认MVC模板包含“Content”文件夹。由于您重定向到内容/索引并且索引很可能是默认操作,因此您实际上会被重定向到/ content - 这是内容目录而不是您的控制器。如果我是你,我会为你的控制器选择另一个名字以避免冲突。