[英]Error using URL.Content in ASP.Net MVC
I have the following ASP.NET MVC page written in razor: 我有以下用剃刀编写的ASP.NET MVC页面:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>SelectorTests</title>
<link href="@{ Url.Content("~/Content/themes/base/jquery-ui.css"); }" rel="stylesheet" type="text/css" />
<script src="@{ Url.Content("~/Scripts/jquery-1.4.4.min.js"); }" type="text/javascript"></script>
<script src="@{ Url.Content("~/Scripts/jquery-ui.min.js"); }" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('h1').css('background-color', 'purple');
});
</script>
</head>
<body>
<div>
<h1>My Header</h1>
foobar
</div>
</body>
</html>
URL.Content isn't working properly. URL.Content无法正常工作。 When I do a View Source in FF, the relevant lines come back as
当我在FF中执行查看源时,相关的行返回为
<link href="" rel="stylesheet" type="text/css" />
<script src="" type="text/javascript"></script>
<script src="" type="text/javascript"></script>
Please assist. 请协助。
You're using curly braces when there is no need to. 你没有必要使用花括号。
<link href="@{ Url.Content("~/Content/themes/base/jquery-ui.css"); }" rel="stylesheet" type="text/css" />
Should be: 应该:
<link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
You need only wrap code in curly braces when there is no return value. 当没有返回值时,您只需要在花括号中包装代码。 For example if you were declaring a variable.
例如,如果您要声明变量。 You would not need curly braces to then output the contents of the variable.
您不需要花括号来输出变量的内容。
@{
var foo = "bar";
}
<p>@foo</p>
Rich 丰富
Try the following 请尝试以下方法
<link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.min.js")" type="text/javascript"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.