为什么我会收到 Lightbox MVC razor 错误?
我正在尝试使用 Lightbox 显示图像,其逻辑如下:
public ActionResult displayImg()
string lbx = "<a href=\"~/Content/Images/lighthouse.jpg\" rel=\"lightbox\"></a>";
return View (lbx);
但它给出了一个错误:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Illegal characters in path.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Illegal characters in path.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
I'm trying to display an image using Lightbox with the logic something like this:
public ActionResult displayImg()
string lbx = "<a href=\"~/Content/Images/lighthouse.jpg\" rel=\"lightbox\"></a>";
return View (lbx);
But it gives an error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Illegal characters in path.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Illegal characters in path.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将
作为视图名称传递,该视图名称将被转换为项目中的文件名。
这不是一个有效的文件名。
您可能想要返回
Content(...)
,它返回一个文字字符串。您还需要使用 URL 类映射路径。
You're passing
<a ...></a>
as a view name, which is translated into a filename in your project.That's not a valid filename.
You probably want to return
Content(...)
, which returns a literal string.You also need to map the path using the URL class.