Rohit Sharma
Rohit Sharma

Reputation: 31

How to make static url dynamically in mvc application

I created a website where i passes url like this:

<base href="http://localhost:5423/" />

it all working fine for local.

but now i am deploying on host and problem arises here:

On the same index.vbhtml i have used menues like this:

<li><a class="home" href="Home/Index">Home</a></li>
<li class="wish"><a class="wishlist" href="Products/Index" id="wishlist-total">Products</a></li>
<li><a class="account" href="Home/Contact">Contact Us</a></li>

Now if i am trying with

HttpContext.Current.Request.Url

then its added root path everytime like if i click on Home,it shows correct first time:

http://192.168.1.100/Home/Index

But now if i am clicking again on same link,its adding Home again:

http://192.168.1.100/Home/Home/Index

what should be the solution for this.

Regards,

Upvotes: 0

Views: 523

Answers (1)

Alex Art.
Alex Art.

Reputation: 8781

You can use Url.Action helper

<li><a class="home" href="@Url.Action("Index", "Home")">Home</a></li>
<li class="wish"><a class="wishlist" href="@Url.Action("Index", "Products")" id="wishlist-total">Products</a></li>
<li><a class="account" href="@Url.Action("Contact", "Home")">Contact Us</a></li>

Edit:

To generate absolute URLs try:

Url.Action("Index", "Home", null, Request.Url.Scheme)
Url.Action("Index", "Products", null, Request.Url.Scheme)
Url.Action("Contact", "Home", null, Request.Url.Scheme)

Upvotes: 1

Related Questions