ASP.NET Core - How to get parameter from url

Viewed 717

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 Answers

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
Related