Illegal characters in path when calling the index view from my controller

后端 未结 2 346
情书的邮戳
情书的邮戳 2020-12-17 08:42

I am receiving an ArgumentException when invoking the index action of one of my controllers and I am not sure why. The error message is the following:

Server Error

2条回答
  •  暖寄归人
    2020-12-17 09:06

    The ambiguity comes from the fact that you are using string as model type. This ambiguity could be resolved like this:

    public ActionResult Index()
    {
        var glaccounts = db.GLAccounts.ToString();
        return View((object)glaccounts);
    }
    

    or:

    public ActionResult Index()
    {
        object glaccounts = db.GLAccounts.ToString();
        return View(glaccounts);
    }
    

    or:

    public ActionResult Index()
    {
        var glaccounts = db.GLAccounts.ToString();
        return View("Index", glaccounts);
    }
    

    Notice the cast to object to pick the proper method overload as there is already a View method which takes a string argument which represents the view name so you cannot throw whatever you want to it => if it's a string it must be the name of the view and this view must exist.

提交回复
热议问题