c# - Showing MVC URL Path through Controller/Action/RouteValues combination -


i had doubt following:

when use following code:

@(html.actionlink("click me", "action", new {queryname = viewbag.queryname})) 

i html output this: <a href="http://localhost/controllername/action?queryname=098"> click me </a>

ok, if want have following html output?

<span > want "href" part of action link http://localhost/controllername/action?queryname=098 , without "a" tag </span>

do have write extension or have preexistent provision it?

i hope clear enough.

thanks

update

so far wrote extension, not best way it, can see below, needed it:

public static class actionurlpathextension {     public static mvchtmlstring actionurlpath(this htmlhelper helper ,  string actionname, string controllername, object routevalues)     {         string resulturl=linkextensions.actionlink(helper," ",actionname,controllername, routevalues, new object()).tohtmlstring();         resulturl= resulturl.replace("</a>","") .replace("<a href=\"","") .replace("\">","").trim() ;          return mvchtmlstring.create(helper.viewcontext.httpcontext.server.urldecode(resulturl));     } } 

in html used this:

<span>now can paste url in address bar : @(html.actionurlpath("carregarfiltros", "filtros", new { queryid = "%0" , nocache = new random().next(0,1989)  }))</span> 

you can use url.action, so:

@url.action("action", new { queryname = viewbag.queryname }) 

or if need qualified url:

@url.action("action", "controller", new { queryname = viewbag.queryname }, "http") 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -