ASP.NET MVC 4 View ( Razor ) – Controller + Partial View 格式

ASP.NET MVC 4 View ( Razor ) – Controller + Partial View 格式

   Controller
 
   namespace NetworkAssetWeb.Controllers
   {
      public class HomeController : Controller
      {
         public ActionResult CatItem(string category)
         {
            DAO dao = new DAO();
            CategoryDatail CatDetail = new CategoryDatail();
 
            … …
 
            if (dao.getAuth(System.Web.HttpContext.Current.User.Identity.Name))
            {
               … …
 
               ViewBag.ErrorMessage = "";
               return View("Item", CatDetail);
            }
            else
            {
               ViewBag.ErrorMessage = "Access Denied";
               return View("Item", null);
            }
         }
 
         … …
 
         public ActionResult LocationCount(string category)
         {
            DAO dao = new DAO();
 
            if (category != null)
               return PartialView(dao.getLocationCount(category));
            else
               return PartialView(dao.getLocationCount("All"));
         }
 
         public ActionResult ItemStatus(string category)
         {
            DAO dao = new DAO();
 
            if (category != null)
               return PartialView(dao.getItemStatus(category));
            else
               return PartialView(dao.getItemStatus("All"));
         }
 
         public ActionResult ItemSubType(string category)
         {
            DAO dao = new DAO();
 
            if (category != null)
               return PartialView(dao.getItemSubType(category));
            else
               return PartialView(dao.getItemSubType("All"));
         }
 
         public ActionResult SystemCount()
         {
            DAO dao = new DAO();
 
            return PartialView(dao.getSystemCount());
         }
 
         public ActionResult ItemMaintenanceDetail(string category)
         {
            DAO dao = new DAO();
 
            if (category != null)
               return PartialView(dao.getInServiceItemWithMain(category));
            else
               return PartialView(dao.getInServiceItemWithMain("All"));
         }
 
         public ActionResult ExistingMaintenanceVendor(string category)
         {
            DAO dao = new DAO();
 
            if (category != null)
               return PartialView(dao.getExistingMaintenanceVendor(category));
            else
               return PartialView(dao.getExistingMaintenanceVendor("All"));
         }
 
         public ActionResult PurchaseYearCount(string category)
         {
            DAO dao = new DAO();
 
            if (category != null)
               return PartialView(dao.getPurchaseYearCount(category));
            else
               return PartialView(dao.getPurchaseYearCount("All"));
         }
      }
   }
 
   Main View
 
   @model NetworkAssetDAO.CategoryDatail
 
   < div id="topmenu">
 
      < a class="menu" href="/Home/Overall">Overall</a>
      < a class="menu @(ViewBag.SecuritySelected)" href="/Home/CatItem?Category=Security">Security & Internet</a>
      < a class="menu @(ViewBag.BackupSelected)" href="/Home/CatItem?Category=Backup">Backup</a>
      < a class="menu @(ViewBag.NetworkedStorageSelected)" href="/Home/CatItem?Category=Networked Storage">Networked Storage</a>
      < a class="menu @(ViewBag.SwitchRouterSelected)" href="/Home/CatItem?Category=SwitchRouter">Switch & Router</a>
      < a class="menu @(ViewBag.ServerSelected)" href="/Home/CatItem?Category=Server">Server</a>
      < a class="menu @(ViewBag.ToBeCategorizedSelected)" href="/Home/CatItem?Category=To Be Categorized">To Be Categorised</a>
      < a class="menu @(ViewBag.OthersSelected)" href="/Home/CatItem?Category=Others">Other Infrastructure Hardware</a>
      < a class="menu" href="/Home/Software">Software</a>
 
      @{
         if(Model != null)
         {
            < a class="Export" href="@(ViewBag.ExportAllCategoryLink)" style="… …">Export to Excel File ( All Categories )</a>
            < a class="Export" id="ExportExcelIndividual" href="@(ViewBag.ExportLink)" style="… …">Export to Excel File</a>

         }
      }
 
      < div style="… …">@ViewBag.ErrorMessage</div>
      < div style="… …">@ViewBag.LoginName</div>
 
   </div>
 
   @{
 
      if(Model != null)
      {
 
         … …
 
         < div id="content">
 
            … …
 
            < div id="PO_Tbl" class="Tbl">
 
               < table border="0" cellpadding="8" cellspacing="0" width="100%" style="width:100%;">
                  <tr>
                     < td align="center" width="20%">@{Html.RenderAction("PurchaseYearCount");}</td>
                     < td align="center" width="20%">Reserved.</td>
                     < td align="center" width="20%">Reserved.</td>
                     < td align="center" width="20%">Reserved.</td>
                     < td align="center" width="20%quot;>Reserved.</td>
                  </tr>
               </table>
 
            </div>
 
            < div id="Main_Tbl" class="Tbl">
 
               <table border="0" cellpadding="8" cellspacing="0" width="100%" style="width:100%;">
                  <tr>
                     <td valign="top" width="20%">@{Html.RenderAction("ItemMaintenanceDetail");}</td>
                     <td valign="top" width="20%">@{Html.RenderAction("ExistingMaintenanceVendor");}</td>
                     <td align="center" width="20%">Reserved.</td>
                     <td align="center" width="20%">Reserved.</td>
                     <td align="center" width="20%">Reserved.</td>
                  </tr>
               </table>
 
            </div>
 
            < div id="General_Tbl" class="Tbl">
 
               <table border="0" cellpadding="8" cellspacing="0" width="100%" style="width:100%;">
                  <tr>
                     <td valign="top" width="20%">@{Html.RenderAction("LocationCount");}</td>
                     <td valign="top" width="20%">@{Html.RenderAction("ItemStatus");}</td>
                     <td valign="top" width="20%">@{Html.RenderAction("ItemSubType");}</td>
                     <td valign="middle" width="20%">Reserved.</td>
                     <td valign="middle" width="20%">Reserved.</td>
                  </tr>
               </table>
 
            </div>
 
         </div>
 
         … …
 
      }
   }
 

   Partial View ( Location Count )
 
   @model List<NetworkAssetDAO.LocationCount>
 
   < div class="dashboarditem_header"><strong>Item Location Details</strong></div>
 
   < table cellspacing="0" cellpadding="0">
 
      <tr>
         <th valign="middle" align="left">< div>Building</div></th>
         <th valign="middle" align="right">< div>Count</div></th>
      </tr>
 
      @{
 
         int LocationSum = 0;
 
         foreach (var item in Model)
         {
 
            <tr>
 
               @if (item.Location == "??" || item.Location.Trim() == "" || item.Location == "Unknown")
               {
                  <td align="left">< div class="LocationDashBtn">Unknown</div></td>
               }else{
                  <td align="left">< div class="LocationDashBtn">@item.Location</div></td>
               }
 
               <td align="right">< div>@item.Count</div></td>
 
            </tr>
 
            LocationSum += item.Count;
 
         }
 
      }
 
      <tr>
            <td align="left">< div><strong>Total Item in this Category :</strong></div></td>
            <td align="right">< div>@(LocationSum)</div></td>
      </tr>
 
   </table>