简体   繁体   English

ASP.NET MVC中的Url.Content问题

[英]Problem with Url.Content in ASP.NET MVC

For some reason, I am getting a runtime exception when I try to use Page.ResolveURL or Url.Content within the default masterpage (Site.Master) in my newly created asp.net mvc application. 由于某种原因,当我尝试在新创建的asp.net mvc应用程序的默认母版页(Site.Master)中使用Page.ResolveURL或Url.Content时,出现运行时异常。 This is very odd, because I have been using the ResolveURL helper function in .NET for years without issue. 这很奇怪,因为多年来我一直在.NET中使用ResolveURL helper函数,而没有出现任何问题。 Here is my code snippet: 这是我的代码段:

<link href="<%= Url.Content("~/css/style.css"); %>" rel="stylesheet" type="text/css" />

And here is the runtime error that occurs on the very same line: 这是在同一行上发生的运行时错误:

Compiler Error Message: CS1026: ) expected

If I change the href to a static URL, everything is fine. 如果我将href更改为静态URL,一切都很好。 Also, this is a brand new ASP.NET mvc project....this was the first line of code that I changed. 另外,这是一个全新的ASP.NET mvc项目。...这是我更改的第一行代码。

删除分号

Remove the semi-colon from the end. 从末尾删除分号。 Some MVC helper methods return strings in which case they should appear between <%= %> tags which is appropriate in this case. 一些MVC帮助器方法返回字符串,在这种情况下,它们应该出现在<%= %>标记之间,这在这种情况下是合适的。 When using helper methods that return something, you leave the semi-colon off of the end. 当使用返回某些内容的辅助方法时,可以将分号放在最后。

Other helper methods return nothing (eg, Html.RenderPartial) in which cases you use <% %> tags and here you end your code expression with a semi-colon. 其他帮助程序方法不返回任何内容(例如,Html.RenderPartial),在这种情况下,您使用<% %>标记,并且在此处使用分号结束代码表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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