Finding ResolveUrl/ResolveClientUrl Equivalents For Razor?
Feb 16, 2011
So I've started using the <%: Url.Content(~/site/blah) %> syntax as standard for CSS, JScript and Image urls - solves a lot of issues indeed; and it's at least consistent beween WebForms and Razor pages (not all of my devs will be doing Razor, and yet they will still be working on this platform I've produced).
However, for something that I'm doing at the moment I could really do with a way to take a relative Url written in a Razor page and, at run time, resolve it to the correct server side file, before turning it back into an absolute Url for the client. Url.Content doesn't do anything with relative Urls.
So, basically, I want either an equivalent of ResolveUrl or ResolveClientUrl at the Razor level.
I would like this to enable terser (and more tolerant to renaming) resource paths in some of my MVC views, which can be a few folders further down from the root, and whose content folder would be more easily expressed as a relative path - so I could have:
folderfolderviewssharedlayout.cshtml
and
folderfoldercontentsite.css
(I've inferred the use of a layout page, also, to mirror the kind of issues that are addressed by ResolveUrl and the re-basing that WebForms does)
Using Url.Content as it is, I would need to specify the full path:
Url.Content("~/folder/folder/content/site.css")
But what I would like is
Url.Content("../../site.css")
And have that work, of course, regardless of how many paths there are in the current request's route.
Of course I can get this to work in WebForms, if I ditch the Url.Content call and just rely on url rebasing.
Is there any equivalent in Razor?
View 1 Replies
Similar Messages:
Aug 22, 2010
I have the following:
[Code]....
And I am trying to do the same with Razor:
[Code]....
But I keep having the error:
Compiler Error Message:
CS0103: The name 'ResolveUrl' does not exist in the current context
What am I doing wrong?
View 6 Replies
Jan 4, 2010
I use ResolveClientUrl to include css files in my page. When launched through web-server everything is OK, but in design mode css styles are not applied to the page. I use VS 2010 beta 2.
<link href= "<%= ResolveClientUrl("~/Styles/Site.css") %>" rel="stylesheet" type="text/css" />
Same thing happens when I use any expression to specify an url for css How can I fix it? Or is it a bug of beta?
View 1 Replies
May 4, 2010
Is there an equivalent of the GridView.RowDataBound event for the DetailView and FormView controls in ASP.NET 3.5?I need to manipulate data after Selecting it from my database, but before it gets presented to the user. I've read the documentation but I think I've missed something because I can only find FormView.DataBound which is called after the entire control has been data bound. Something like an ItemDataBound event would be what I need....?!?
View 6 Replies
Dec 14, 2010
I use the following my .net applications to resolve the path to an image or css file or javascript file.
<%=ResolveUrl("~/Scripts/myscript.js")%>
<%=ResolveUrl("~/images/myimage.jpg")%>
All my pages and controls inherit from a base page or base user control.
I have tried but didnt succeed in overriding the ResolveUrl method so that I could include some custom logic in the files path.
how I might override the ResolveUrl method? Alternative is to create my own custom method that does similar but would prefer to work with ResolveUrl.
View 2 Replies
Feb 4, 2011
I am looking for a way to resolve a relative url the way you would with a page or control instance (MSDN Docs) such as:
Page.ResolveUrl("~/common/Error.aspx");
...but when I only have an HttpContext available to me, such as when I am in a HttpHandler.
Will I need to use a custom function, such as the one seen here?
Or is there a way to get at the underlying function used by the Page.
View 2 Replies
Jun 23, 2010
How do you resolve a url like "../../images/test.png" to [URL] in a static asp.net web method?
View 2 Replies
Feb 14, 2010
I want to use .sitemap file,but how to use Page.ResolveUrl in it. Because i have used UrlRewriting so it url are virtual.tell me if another way of doing this.
View 1 Replies
Mar 31, 2010
I'm trying to use ResolveUrl() to set some paths in the code behind of a custom ASP.NET user control. The user control contains a navigation menu. I'm loading it on a page that's loading a master page.
When I call ResolveUrl("~") in my user control it returns "~" instead of the root of the site. When I call it in a page I get the root path as expected. I've stepped through with the debugger and confirmed, ResolveUrl("~") returns "~" in my user control code behind.
Is there some other way I should be calling the function in my user control code behind to get the root path of the site?
View 4 Replies
Apr 1, 2010
I am trying to do a correct path javascript like this to an image but when compiling this code, I receive the error:
"Too many characters in character literal"
I have tried to figure it out but it seems correct but something might be wrong. I have to use ResolveUrl to go back to the rootdirectory.
[Code]....
View 2 Replies
Dec 14, 2010
We tried to add a Entity model using Razor here was the syntax: @ModelType BID.Data.Entities.PlumbingPermit
View 4 Replies
Feb 28, 2011
I'm following the ASP.NET MVC Tutorial and having started in VB.NET I'm having trouble converting the following razor code:
I have got
<ul>
@For Each g As MvcApplication1.Genre In Model
<li> @g.Name </li>
Next
</ul>
but getting
Attribute Sepcifier is not a complete statement on both the <li> tags. I understand I need to use line continuation but can't figure out where.
View 3 Replies
Feb 4, 2011
I'm all new at MVC, so how do I access the users Profile attributes which are defined in the web.config file.With WebForms I would normally do something like this:
[Code]....
[Code]....
I really can't figure out how to do it in MVC 3 Razor.Would really like to see a working example,
View 1 Replies
Jan 23, 2011
Now that ASP.NET MVC 3 with the new Razor engine has been officially released, is there any official documentation for it?The question asp.net mvc3 razor documentation? has some good links to introductory texts. But I'm looking for a reference documentation that contains a complete description of all @keywords.
View 2 Replies
Sep 15, 2010
Here is what I would like to express by Razor:
<b>@parameterMapping.Title</b> (Category: @parameterMapping.Category.Title, Regexp: @parameterMapping.Regexp)
But to make it parseable I have to write it this way:
<b>@parameterMapping.Title</b> <text>(Category: </text> @parameterMapping.Category.Title <text>, Regexp:</text> @parameterMapping.Regexp <text>)</text>
Are there better ways to solve this problem?
View 1 Replies
Feb 27, 2011
How does one create a .cshtml page in an ASP.NET web application? The option to choose Razor is obvious when using MVC - it appears when adding a view. But I can't seem to figure out how to accomplish this in a plain ASP.NET Web Application. Is it even possible?
View 1 Replies
Jan 18, 2011
I've recently switched over to using the Razor view engine, and I want to specify a namespace to use in a view. I've tried adding an entry to the Web.config file, ie:
[Code]....
But none of my views recognise any of the classes inside that namespace, so I have to declare the namespace in every view that needs it. why the Web.config approach isn't working?
View 13 Replies
Sep 2, 2010
If I look at the Razor View Engine, then I see a very nice and concise syntax that is not particularly tied to generating html. So I wonder, how easy would it be to use the engine outside asp.net in a "normal" .net environment for example to generate text, code,...
View 3 Replies
Jul 10, 2010
Will or is T4MVC compatible with Razor?
[code]....
Does it make sense to use both at same time?
View 6 Replies
Nov 24, 2010
I've just installed the new MVC3 RC ,and have no idea about where the *.ascx template stuffs live in?
View 1 Replies
Mar 11, 2011
I try to generate this HTML code with Razor:
[Code]....
This is my Code in .cshtml, i have to select the "current" Style and insert <span> </span> tags wraping item.Text, but it doesnt work ....
[Code]....
View 2 Replies
Feb 10, 2011
what is the best way to migrate MVC2 project to MVC 3.
View 4 Replies
Apr 4, 2011
<span class="abc">abc</span>
I want to have @postid as well in there so that the name of the class is generated as abc123. How can i do that?
View 1 Replies
Mar 15, 2011
I would like to display 3 three userControls on a home view
UserControl1 ==> Enterprise Entity partial view
UserControl2 ==> Client Entity partial view
UserControl3 ==> Biling Entity partial view
A submit button to save all values
So my home will display the 3 partial views and enable me; when I click submit button ;
to save Enterprise Data, Client Data and Biling Data.
View 1 Replies
Feb 19, 2011
It seems that using Local resources is much more complicated when using Razor. I recently converted an MVC 2 app I was working on to MVC 3. The conversion went well but accessing LocalResources doesn't work and I can't get it to work. In MVC 2 I created an App_LocalResources folder in the /Views/Home folder and created an Index.aspx.resx resource file. In the Index View I could access the local resources with
<%: GetLocalResourceObject("FirstName") %>
Simple, out-of-the-box functionality, as it should be. Razor doesn't understand this. It seems that in Razor you have to use @HttpContext.GetLocalResourceObject(<virtual-path>, <resource-name-key>). I've tried everything for virtual-path but nothing seems to work ("~/", "~/Views/Home/App_LocalResources", etc.). I tried to directly access the resource file by providing the complete namespace, like you do with global resources (which works fine in Razor), but then it errors stating that the culture is required. Intellisense allows you to build the reference to the resource property but Razor doesn't understand it.
Of course an alternative could be to simply use the ASPX rendering engine in MVC 3, but I want to use Razor. Does anyone know an out-of-the-box method (not some exotic work-around) for accessing the LocalResources in an MVC 3 app using Razor?
View 2 Replies