We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,278 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Problems writing out URLs in MVC View

I'm trying to write out animals from a database. All the samples I see for creating View pages have hard-coded "nodes" in the URLs, but since I'm reading my data from a database, I don't know all the "nodes".

I can get my first view to work but my second one doesn't write out the correct URL to go to the third one. So, for example, I want my URLs to be:

/animals/
/animals/canines/
/animals/canines/schnauzer


I have the default route setup:

routes.MapRoute( _
             "Default", _
             "{controller}/{action}/{id}", _
             New With {.controller = "Home", .action = "Index", .id =
 UrlParameter.Optional} _
         )

The first URL works great and I can list the animal groups on the first one along with the correct links to the second URLs. I do that as follows:

for each animal in model
     Html.ActionLink(animal.animal_name,animal.animal_name.Trim) 
next

For some reason, by simply adding the animal_name as the link, it concatenates it onto the current path.

I also can get the canine groups written out on the second (so I know my model is working), however the URL.Action on that second "canines" page loses the "canines" in the URL so it renders as:

/animals/schnauzer

In this case, it isn't adding the node on to the end of the URL, it is replacing the last node. I've tried every way I can think of to write out the link including:

<a href="<%= url.action(canine.dog_name.Trim)) %>">
    <a href="<%= Url.Content("~" & url.action(canine.dog_name.Trim)) %>">

and a few others that aren't worth showing. :)

... I'm guessing I'm missing something in a route path but what is it? It can't be that I have to know the path I'm at on every page in order to write out the URL - can it?

Thanks in advance for your help!

1
Contributor
0
Replies
1
View
rss2363
Newbie Poster
1 post since Apr 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0537 seconds using 2.69MB