调用从我的控制器索引视图时路径中具有非法字符 [英] Illegal characters in path when calling the index view from my controller
问题描述
我调用我的控制器之一的索引操作时收到一个ArgumentException,我不知道为什么。该错误消息是:
中的服务器错误'/'应用。
路径中具有非法字符。
[ArgumentException的:路径中具有非法字符]
System.IO.Path.CheckInvalidPathChars(字符串路径)+126
System.IO.Path.Combine(PATH1字符串,字符串PATH2)+38
我不知道为什么会这样。这里是从控制器code:
公众的ActionResult指数()
{
变种glaccounts = db.GLAccounts.ToString();
返回查看(glaccounts);
}
模糊性来自于事实,你正在使用字符串
的型号。这种不确定性就可以解决这样的:
公众的ActionResult指数()
{
变种glaccounts = db.GLAccounts.ToString();
返回查看((对象)glaccounts);
}
或
公众的ActionResult指数()
{
对象glaccounts = db.GLAccounts.ToString();
返回查看(glaccounts);
}
或
公众的ActionResult指数()
{
变种glaccounts = db.GLAccounts.ToString();
返回视图(指数,glaccounts);
}
注意投反对挑选适当的方法重载因为已经有一个查看
方法,需要其重新$ P $字符串参数psents视图名称,以便您不能把任何你想它=>如果它是一个字符串,它必须是视图的名称,这种观点必须存在。
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 in '/' Application.
Illegal characters in path.
[ArgumentException: Illegal characters in path.]
System.IO.Path.CheckInvalidPathChars(String path) +126
System.IO.Path.Combine(String path1, String path2) +38
I am not sure why this is happening. here is the code from the controller:
public ActionResult Index()
{
var glaccounts = db.GLAccounts.ToString();
return View(glaccounts);
}
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.
这篇关于调用从我的控制器索引视图时路径中具有非法字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!