加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-3 – 从我的控制器调用索引视图时路径中的非法字符

发布时间:2020-12-15 19:07:51 所属栏目:asp.Net 来源:网络整理
导读:我收到一个ArgumentException,当调用我的控制器之一的索引操作,我不知道为什么。错误消息如下: ‘/’应用程序中的服务器错误。 路径中的非法字符。 [ArgumentException: Illegal characters in path.] System.IO.Path.CheckInvalidPathChars(String path)
我收到一个ArgumentException,当调用我的控制器之一的索引操作,我不知道为什么。错误消息如下:

‘/’应用程序中的服务器错误。

路径中的非法字符。

[ArgumentException: Illegal characters in path.]
 System.IO.Path.CheckInvalidPathChars(String path) +126
 System.IO.Path.Combine(String path1,String path2) +38

我不知道为什么会发生这种情况。这里是控制器的代码:

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

解决方法

模糊性来自于你使用字符串作为模型类型。这种模糊性可以这样解决:
public ActionResult Index()
{
    var glaccounts = db.GLAccounts.ToString();
    return View((object)glaccounts);
}

要么:

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

要么:

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

注意,对象的转换选择正确的方法重载,因为已经有一个View方法,它接受一个表示视图名称的字符串参数,所以你不能把任何你想要的东西=>如果它是一个字符串,它必须是视图的名称,并且此视图必须存在。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读