c# - What using directive can I implement in my .cs file that will let me use the "WebPageExecutingBase.Href()" Method? -


i have .cs file generates html. within it, make code little more fool proof using webpageexecutingbase.href() method, have done in many cshtml files before (mainly use of tilde ~).

however, links broken on generated html if include tilde:

string html = "<a href=\"~/somefolder/somefile.cshtml\">link</a>"; //generates broken link. 

but can't seem import appropriate using directive use href() method in environment of .cs file alone.

i have tried:

using system.web;  using system.web.webpages; 

and trying use webpageexecutingbase.href(), while "webpageexecutingbase" part shows in intellisense, "href()" not (and, in fact, generates server-side error demanding second 'object' argument, have used same method 1 argument multiple times before).

i have tried info on here: http://msdn.microsoft.com/en-us/library/system.web.webpages.webpageexecutingbase(v=vs.111).aspx no avail.

i thought had right, i'm not sure if can use method here @ all.

is there way implement href() method (or same functionality therein) within html generated in string in .cs c# file?

the href method not intended use in classes. should use virtualpathutility instead. need include using directive system.web this:

string html = string.format("<a href=\"{0}\">link</a>", virtualpathutility.toabsolute("~/somefolder/somefile.cshtml")); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -