我如何使用@ Url.Content()非MVC剃刀网页? [英] How do I use @Url.Content() in non-MVC Razor webpage?

查看:178
本文介绍了我如何使用@ Url.Content()非MVC剃刀网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我使用具有安装的NuGet包的Microsoft.AspNet.Razor Web应用程序。

在Web窗体页面(的.aspx),我可以使用RESOLVEURL(),但在剃刀页(的.cshtml),我得到这个错误 - >

 X:\\来源\\ Foo.Dealer \\ Foo.Dealer.WebApp.Mobile \\会员\\ DmsDashboard.cshtml(103):错误CS0103:URL的名称不存在在目前情况下

源 - code在这里..

  @section HeadJavascriptLibraryFile
{
    <脚本类型=文/ JavaScript的SRC =@ Url.Content(〜/脚本/网页/设置-dmsdashboard.js)>< / SCRIPT>
}

 < IMG SRC =@(Url.Content(〜/图片/杂项/ reportandpiechart2.png))ALT =/>

来源$ C ​​$ C的要求...

  // LayoutMembmerGeneral.cshtml
@using Foo.Dealer.WebApp.Mobile.Infrastructure;
@ {
    如果(LoginManagementTools.DealerUserLoginValidation_BrowsingPage(HttpContext.Current.Request,HttpContext.Current.Response,HttpContext.Current.Session)== FALSE){}
}<!DOCTYPE HTML>
< HTML和GT;
< HEAD>
  <标题> @ Page.Title< /标题>
  @RenderSection(HeadJavascriptLibraryFile,FALSE)
< /头>
<身体GT;
@RenderBody()
< /身体GT;
< / HTML>//DmsDashboard.cshtml ...
@using Foo.Dealer.WebApp.Mobile.Infrastructure
@using System.Web.Mvc;@ {
    Page.Title =一个新的黎明在汽车定价;
    布局=LayoutMemberGeneral.cshtml;
}
@section HeadJavascriptLibraryFile
{
}< D​​IV ID =WebLayout1>
    < IMG SRC =@ Url.Content(图像/杂项/ reportandpiechart2.png),ALT =/>
< / DIV>


解决方案

该网址助手似乎并没有在ASP.Net网页存在(这是你试图做什么本质),但你可以简单地使用以下code,以达到同样的效果:

< IMG SRC =〜/图片/杂项/ reportandpiechart2.pngALT =/>

代字号(〜)引用应用程序根和当页面被编译并被发送到客户端被转化

Since I'm using Web Application having NuGet Package's Microsoft.AspNet.Razor installed.

In WebForm pages (.aspx), I can use ResolveUrl() but in Razor pages (.cshtml), I get this error -->

"x:\Source\Foo.Dealer\Foo.Dealer.WebApp.Mobile\Member\DmsDashboard.cshtml(103): error CS0103: The name 'Url' does not exist in the current context"

Source-Code here..

@section HeadJavascriptLibraryFile
{
    <script type="text/javascript" src="@Url.Content("~/scripts/webpages/setting-dmsdashboard.js")"></script>
}

and

<img src="@(Url.Content("~/images/miscellaneous/reportandpiechart2.png"))" alt="" />

Source Code as requested...

//LayoutMembmerGeneral.cshtml
@using Foo.Dealer.WebApp.Mobile.Infrastructure;
@{
    if (LoginManagementTools.DealerUserLoginValidation_BrowsingPage(HttpContext.Current.Request, HttpContext.Current.Response, HttpContext.Current.Session) == false) { }
}<!DOCTYPE html>
<html>
<head>
  <title>@Page.Title</title>
  @RenderSection("HeadJavascriptLibraryFile", false)
</head>
<body>
@RenderBody()
</body>
</html>

//DmsDashboard.cshtml...
@using Foo.Dealer.WebApp.Mobile.Infrastructure
@using System.Web.Mvc;

@{
    Page.Title = "A New Dawn In Auto Pricing";
    Layout = "LayoutMemberGeneral.cshtml";
}
@section HeadJavascriptLibraryFile
{
}

<div id="WebLayout1">
    <img src="@Url.Content("images/miscellaneous/reportandpiechart2.png")" alt="" />
</div>

解决方案

The URL helper doesn't seem to exist in ASP.Net Web Pages (which is essentially what you are attempting to do), but you can simply use the following code to achieve the same effect:

<img src="~/images/miscellaneous/reportandpiechart2.png" alt="" />

The tilde (~) references the application root and is transformed when the page is compiled and sent to the client.

这篇关于我如何使用@ Url.Content()非MVC剃刀网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆