title: if else condition in view for displaying webgrid in mvc
body: <p>i am working on a project in which i have to display some webgrids. Those webgrids have the same datasource but they should be divided based on some condition. Here is my code for controller:</p>
  
  <pre><code>public ActionResult Index()
          {
  
              SqlCommand cmd = new SqlCommand("select * from Bspecial_Ad_management_tbl where ", con);
              con.Open();
              SqlDataReader dr = cmd.ExecuteReader();
              List&lt;AddDetailModel&gt; model = new List&lt;AddDetailModel&gt;();
              while (dr.Read())
              {
                  model.Add(new AddDetailModel()
                  {
                      AdName = dr["Ad_name"].ToString(),
                      AdType=dr["Ad_type_name"].ToString(),
                      PartnerName=dr["Partner Name"].ToString(),
                      hrefurl=dr["Ad_url"].ToString(),
                      startDate=dr["Start_date"].ToString(),
                      endDate = dr["End_date"].ToString(),
                      tagName = dr["Tag"].ToString(),
                      AdPath= dr["Ad_image_path"].ToString(),
                      Status = dr["Status"].ToString()
                  });
              }
              dr.Close();
              return View(model);
          }
  </code></pre>
  
  <p>And this is my view :</p>
  
  <pre><code>@model IEnumerable&lt;EShopPartnerSetting.Models.AddDetailModel&gt;
  @{
     {
          Layout = "~/Views/Shared/AdminLayout.cshtml";
      }
  
  }
  @{
      var grid = new WebGrid(source: Model,
                                                defaultSort: "First Name",
                                                rowsPerPage: 5, fieldNamePrefix: "wg_",
                                                canPage: true, canSort: true,
                                                pageFieldName: "pg", sortFieldName: "srt"
                                                );  
  }
  &lt;html&gt;
  &lt;head&gt;
     Some unrelated scripts here
  &lt;/head&gt;
  &lt;body&gt;
      @using (Html.BeginForm())
      {
          @Html.ValidationSummary(true)
          &lt;table width="960" border="0" align="center" cellpadding="0" cellspacing="0"&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;div class="maindiv"&gt;
                          &lt;div class="hd"&gt;
                              &lt;h1&gt;
                                  Ad Management&lt;/h1&gt;
                          &lt;/div&gt;
                          &lt;div class="bd"&gt;
                              &lt;table align="center" cellpadding="0" cellspacing="0" width="100%"&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          &lt;input id="new" type="button" value="Create New Ad" style="color: #FFFFFF; background-color: #1688C6;" /&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;
                                          &amp;nbsp;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td align="center"&gt;
                                      &lt;span&gt;Bottom Banner&lt;/span&gt;
                                          @grid.GetHtml(tableStyle: "listing-border", headerStyle: "gridhead", footerStyle: "paging", rowStyle: "td-dark", alternatingRowStyle: "td-light",
                              columns:
                                  grid.Columns(
                                  grid.Column("AdName", "Ad/Campaign", style: "colProductid"),
                                  grid.Column("AdType", "Ad Type", style: "colProductRate"),
                                  grid.Column(header: "Ad", format: @&lt;text&gt;&lt;img src="@item.AdPath"  id="adimg"  alt="YourText" title="Ad Image"  width:"50px" height="50px"&gt;&lt;/text&gt;),
                                  grid.Column("startDate", "Start Date", style: "colCategoryID"),
                                  grid.Column("endDate", "End Date", style: "colCategoryID"),
                                  grid.Column("tagName", "Tag", style: "colCategoryID"),
                                  grid.Column("Status", "IsActive", style: "colCategoryID"),
                                  grid.Column(header: "Edit", format: @&lt;text&gt;&lt;a id="@item.AdName" class="clk"&gt;&lt;img
                                      src="../../Images/edit.png" class="asa" width="25px" height="25px" alt="" style="border: none;" /&gt;&lt;/a&gt;&lt;/text&gt;, style: "colOperation"),
                                  grid.Column(header: "Delete", format: @&lt;text&gt;&lt;a href="@Url.Action("Delete", "Ad", new { aname = item.AdName, apath = item.AdPath, status = item.Status })" onclick="javascript:return ConfirmDelete();"&gt;&lt;img
                                      src="../../Images/delete.png" width="20px" height="20px" alt="" style="border: none;" /&gt;&lt;/a&gt;&lt;/text&gt;, style: "colOperation"),
                                  grid.Column(header: "Status", format: @&lt;text&gt;
                                          &lt;input type="button" class="adbtn" name="one" style="color: #FFFFFF; background-color:#1688C6;" value="Change" onclick="window.location.href='@Url.Action("Add", "Ad", new { ids = item.AdType, path = item.AdPath, status = item.Status })';" /&gt;&lt;/text&gt;, style: "colOperation")
                                  ), mode: WebGridPagerModes.All)
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                      &lt;tr&gt;
                                      &lt;td&gt;
                                          &amp;nbsp;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td width="100%" align="center"&gt;
                                          @* &lt;input id="Submit1" type="submit" value="submit" /&gt;*@
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                              &lt;/table&gt;
                          &lt;/div&gt;
                          &lt;script type="text/javascript"&gt;
                              function ConfirmDelete() {
                                  return confirm("Are you sure you want to delete this?");
                              }
                          &lt;/script&gt;
                      &lt;/div&gt;
                      @* &lt;a id="clk"&gt;click here&lt;/a&gt;*@
                      &lt;div id="dialog" title="Edit" style="overflow: hidden;"&gt;
                      &lt;/div&gt;
                      &lt;div id="newdialog" title="Create" style="overflow: hidden;"&gt;
                      &lt;/div&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      }
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>As you can see from the controller code, i have a parameter called <strong>AdType</strong> there are only  2 values possible for that : 1 and 2. Now i want to display two webgrids, one which has AdType value 1 and the other 2.<strong>Both the webgrids have the same data source</strong>. Thank you</p>