简体   繁体   中英

RediretAction in MVC causes “The Web server is configured to not list the contents of this directory”

I have a contentController like this :

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

That as you can see contains create action .But in the last line ,when it is going to be executed RedirectToAction("Index","content"); i got this error :

    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.

The default MVC template includes a "Content" folder. Since you're redirecting to content/index and index is most likely the default action, you actually get redirected to /content -- which is the content directory rather than your controller. If I were you I would choose another name for your controller to avoid the conflict.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM