How to get Browser Url value in razor view

Total Post:2

Points:14
C#
 256  View(s)
Ratings:
Rate this:

Hi,

I want to get Url value in my razor view for applying an condition on dropdown list. 

Here is my code.

 <div class="col-md-7">

                    <label>Filter By:</label>
                    <select id="filterby" name="FilterBy" style="width: 150px; height: 40px; border: 1px solid #ced4da; border-radius: .25rem;">
                        <option value="name" selected="Condition For Selected item">Name</option>
                        <option value="email" selected="Condition For Selected item">E-mail</option>
                    </select>
                </div>

Please give me solution to accomplish this task....

  1. Post:44

    Points:310
    Re: How to get Browser Url value in razor view

        Hi Sara,

                     You can use Request.QueryString to get Url data in your razor view.

    Please rewrite your code like this :

     <div class="col-md-7">
    
                        <label>Filter By:</label>
                        <select id="filterby" name="FilterBy" style="width: 150px; height: 40px; border: 1px solid #ced4da; border-radius: .25rem;">
                            <option value="name" selected="@(Request.QueryString["UrlFieldValueName"] == "CompareValueName" ? true : false)">Name</option>
                            <option value="email" selected="@(Request.QueryString["UrlFieldValueName"] == "CompareValueName" ? true : false)">E-mail</option>
                        </select>
                    </div>

    I hope this answer is useful for you...

      Modified On Dec-14-2017 12:23:34 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!