开发者

Url Routing in Anchor Tag in asp.net 4.0?

I am using listview and in listview in Item Template, i have anchor tag with href.

<a class="linkbutton" href='<%# string.Format("Movie/Hindi-Movie/{0}/{1}",Eval("MovieId"),Eval("MovieName")) %>'><%#Eval("MovieName")%></a>

and in Global file

i have

routes.MapPageRoute("HindiAboutMovie", "Movie/Hindi-Movie/{MovieId}/{MovieName}", "~/Bollywood/AboutMovie.aspx");

This works fine. but in MovieName i have space between words which makes the url ugly by placing '%' in blank space.

like

http://localhost:5703/Movie/Hindi-Movie/43/Kucch%20Luv%20开发者_开发百科Jaisaa

where i am trying to make

http://localhost:5703/Movie/Hindi-Movie/43/Kucch-Luv-Jaisaa

How to handle this html side in string.Format?

Please guide me.


Have you tried a simple adjustment like:

<a class="linkbutton" href='<%# String.Format("Movie/Hindi-Movie/{0}/{1}",
Eval("MovieId"), Eval("MovieName").Replace(' ', '-'))
%>'><%# Eval("MovieName") %></a>


I tried this approach.

In Html i wrote

<a class="linkbutton" href='<%# string.Format("Movie/Bollywood-Movie/{0}/{1}",Eval("MovieId"),GetMovieName(Eval("MovieName"))) %>'>

and in code behind i wrote a method.

public string GetMovieName(object obj)
    {
        string moviename = Convert.ToString(obj);
        string newmoviename= moviename.Replace(" ", "-");
        return newmoviename;
    }

This did solve my issue at the moment. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜