2

Below is a code that displays my shop item url to my users. The URL (@model.URl) displayed to my user looks like the

https://api.com/folder/?productid=000100&urlProvider=2k4&search=pc

Is there any way i can display the urlProdiver paramater alone in my view like

<a href="@Model.Url["urlProvider"]">

</a>

ShopItem.cs

public class ShopItem
{
   public string Url { get; set; }
}

ShopItem.cshtml

@model ShopItem

<a href="@Model.Url">

</a>

1 Answer 1

1

You can use HttpUtility.ParseQueryString and convert your string Model.Url to Uri object and use like below.

<a href='@HttpUtility.ParseQueryString(new Uri(Model.Url)).Get("urlProvider");'>
    
</a>
Namespace: System.Web
Assembly: System.Web.HttpUtility.dll
Sign up to request clarification or add additional context in comments.

2 Comments

Nice. Actually i want the a href to be the urlProvider instead. Is it that possible ?
Yes, just move code to href as per updated answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.