Display hidden row in asp.net mvc grid - asp.net-mvc

I have made grid with html table tag .in one of TD tag I have this code
<td>
<a onclick="$('#lightBox').css('display','inline')"></a>
<div style="display: none" id="lightbox">
<%--<%Html.RenderAction("LightBox","PremiumSharingAdmin",new {historyId = premium.SharingPremiumHistoryID}); %>--%>
<img src="Storage/Images/<%=premium.SharingPremiumHistoryID %>.jpg" title="image" width="100" height="100"/>
<div>
<textarea readonly="readonly">
<%= premium.Content %>
</textarea>
</div>
<div>
<input type="text" readonly="readonly" value="<%= premium.SharingTitle %>"/>
</div>
</div>
</td>
These tag provide me some extra info from grid row that By default is hidden.
In other side I have Link tag that if user pressed that display that row.
but problem is that when I pressed it, it just show me the first record detail and when I press the others it show me the first row detail.
where is the problem guys ?
This is my whole ASPX view
<% foreach (var premium in Model)
{%>
<tr>
<td style=" font-weight: bold;width: 130px;">
<span ><%= premium.SharingTitle %></span>
</td>
<td style=" font-weight: bold;width: 130px;">
<span ><%= premium.AddedDate.ConvertToPersianDate(true) %></span>
</td>
<td style="width: 130px;">
<span> <%= premium.IsSubmit %></span>
</td>
<td style="width: 130px;">
<span> <%= premium.ResturantName %></span>
</td>
<td style="width: 130px;">
<span> <%= premium.Content %></span>
</td>
<td style="width: 130px;">
<div class="group">
<a class="delete" href="<%= Url.Action("submit", "PremiumSharingAdmin", new {historyId = premium.SharingPremiumHistoryID}) %>" onclick="return confirm('آیا می‌خواهید این خبر را تایید کنید؟');">تایید</a>
</div>
</td>
<td>
<a onclick="$('#lightBox').css('display','inline')"></a>
<div style="display: none" id="lightBox">
<%--<%Html.RenderAction("LightBox","PremiumSharingAdmin",new {historyId = premium.SharingPremiumHistoryID}); %>--%>
<img src="Storage/Images/<%=premium.SharingPremiumHistoryID %>.jpg" title="image" width="100" height="100"/>
<div>
<textarea readonly="readonly">
<%= premium.Content %>
</textarea>
</div>
<div>
<input type="text" readonly="readonly" value="<%= premium.SharingTitle %>"/>
</div>
</div>
</td>
</tr>
<%} %>

You are generating invalid html by giving multiple <div> elements the same id attribute. $('#lightBox').css('display','inline') will return all elements with id="lightbox" but set the style of only the first.
Instead, use class names and use relative selectors. I also recommend you use Unobtrusive Javascript and css, rather tan polluting your mark up with behavior.
Html
<td>
Show
<div class="lightbox">Some content to display</div>
</td>
CSS
.lightbox {
display: none;
}
Script (at bottom of page)
<script>
$('.toggle').click(function () {
if ($(this).hasClass('hidden')) {
$(this).next('div').show();
$(this).text('Hide');
} else {
$(this).text('Show');
$(this).next('div').hide();
}
$(this).toggleClass('hidden');
});
</script>
</body>
Side note: Using RenderAction to render the contents of the hidden div suggest the contents are large and/or you calling a service/database to get the contents. If that's the case you should be loading the contents on demand using ajax (unless your expecting the users to view the details of all rows)

Related

asp.Net Core ViewComponent doesn't show CSS

I'm trying to get to grips with ViewComponents but having trouble trying to get the ViewComponent to reload on a button click. Whats the correct way to handle this?
Initially on the page loading it looks OK like this
In my controller I have
public IActionResult ReloadViewComponent(int characterRegionId, int materialTypeId)
{
return ViewComponent("MarketOrderComponent", new { characterRegionId, materialTypeId});
}
and in my razor view I'm passing parameters to the ReloadViewComponent method
<td><button class="btn btn-sm btn-outline-primary" value="#material.MaterialTypeID" onclick="location.href='#Url.Action("ReloadViewComponent", "BlueprintBreakdown", new { Model.CharacterRegionId, material.MaterialTypeID })'">View</button></td>
full razor view
<body>
<div class="row" style="margin-top:5px;">
<div class="col-lg-4 col-md-12">
<div class="card" style="margin-bottom:0; ">
<div class="header" style="margin-bottom:55px;">
<h2 class="text-primary">Blueprint Breakdown</h2>
</div>
<div class="body">
<div>
<h5 class="text-center">#Model.BlueprintName</h5>
</div>
<div class="row text-center">
<div class="col-6 border-right pb-4 pt-4" style="padding-top:0px !important; padding-bottom:0px !important;">
<img src="#Model.ImageUrl" alt="#Model.BlueprintName">
</div>
<div class="col-6 pb-4 pt-4" style="padding-top:0px !important; padding-bottom:0px !important;">
<img src="#Model.ProductImageUrl" alt="#Model.BlueprintName">
</div>
</div>
<div class="text-center" style="margin-top:5px;">
<text style="font-size:small;">Material Quantity Based on Manufacturing Efficiency</text>
<br />
<text style="font-size:small;">Price Based on Lowest Region Market Sell Orders</text>
<br />
<text style="font-size:small;">Current Region is <span class="text-green">#Model.CharacterRegionName</span></text>
</div>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover table-custom spacing5">
<thead>
<tr>
<th></th>
<th>Material</th>
<th>Quantity</th>
<th>Price</th>
<th>Market</th>
</tr>
</thead>
<tbody>
#foreach (var material in Model.RequiredMaterials)
{
<tr class="text-cente" style="font-size:small;">
<td><img src="#(String.Format("{0}{1}{2}", "https://imageserver.eveonline.com/Type/", material.MaterialTypeID, "_32.png"))" /></td>
<td>#material.TypeName</td>
<td>#material.Quantity</td>
<td>#material.MaterialCost</td>
<td><button class="btn btn-sm btn-outline-primary" value="#material.MaterialTypeID" onclick="location.href='#Url.Action("ReloadViewComponent", "BlueprintBreakdown", new { Model.CharacterRegionId, material.MaterialTypeID })'">View</button></td>
</tr>
}
</tbody>
</table>
</div>
</div>
<div class="col-lg-8 col-md-12">
#await Component.InvokeAsync("MarketOrderComponent", new { Model.CharacterRegionId, Model.RequiredMaterials.First().MaterialTypeID })
</div>
</div>
but when clicking the view button to reload the ViewComponent it is rendered like this.
Note by using the ViewComponent() controller method, your client only gets the component part of the view. So instead of changing the browser's current location, you should send an ajax request and dynamically replace the right side content.
Add an id='MarketOrderComponent'attribute so that we can reference this element later:
<div id='MarketOrderComponent' class="col-lg-8 col-md-12">
#await Component.InvokeAsync("MarketOrderComponent", new { Model.CharacterRegionId, Model.RequiredMaterials.First().MaterialTypeID })
</div>
And change the button click event handler to send an ajax request. For example, in order to reload the market order component, you can change your code as below:
<script>
function reload(url){
return $.ajax({
method:"get",
url:url,
success:function(resp){ $('#MarketOrderComponent').html(resp);},
});
}
</script>
<div class="card" style="margin-bottom:0; ">
...
</div>
<div class="table-responsive">
...
<tbody>
#foreach (var material in Model.RequiredMaterials)
{
<tr class="text-cente" style="font-size:small;">
<td><img src="#(String.Format("{0}{1}{2}", "https://imageserver.eveonline.com/Type/", material.MaterialTypeID, "_32.png"))" /></td>
<td>#material.TypeName</td>
<td>#material.Quantity</td>
<td>#material.MaterialCost</td>
<td>
<button class="btn btn-sm btn-outline-primary"
value="#material.MaterialTypeID"
onclick="var link='#Url.Action("ReloadViewComponent", "BlueprintBreakdown", new { Model.CharacterRegionId, material.MaterialTypeID })'; event.preventDefault(); reload(link)"
>
View
</button>
</td>
</tr>
}
</tbody>
...
</div>
<div id='MarketOrderComponent' class="col-lg-8 col-md-12">
#await Component.InvokeAsync("MarketOrderComponent", new { Model.CharacterRegionId, Model.RequiredMaterials.First().MaterialTypeID })
</div>

View/open file url

I have a view that creates a document with a Title, Date, and name of file that I upload. Once that document is created it is returned to a View that shows the document that I just created and is stored in a database.
Here is the code that creates the document:
<form asp-action="CreateDirectorDocument" role="form" class="form-
horizontal">
<div asp-validation-summary="ModelOnly" class="alert-
danger text-danger"></div>
<div class="form-group">
<div class="col-md-10"><a asp-
action="Index">View Documents</a></div>
</div>
<div class="form-group">
<div class="col-md-10"><label asp-for="Date">
</label></div>
<div class="col-sm-2"><input asp-for="Date" />
</div>
</div>
<div class="form-group">
<div class="col-md-2"><label asp-
for="DocFile"></label></div>
<div class="col-md-4">
<input asp-for="DocFile" type="file"
multiple>
</div>
</div>
<div class="form-group">
<div class="col-sm-2"><label asp-for="Title">
</label></div>
<div class="col-sm-2"><input asp-for="Title"
/></div>
</div>
</form>
View that is return after document has been created:
<table>
<thead>
<tr>
<th class="col-md-2" style="border-bottom: solid">
</th>
<th class="col-md-2" style="border-bottom:
solid">Title</th>
<th class="col-md-2" style="border-bottom:
solid">Date</th>
<th class="col-md-2" style="border-bottom: solid">
</th>
</tr>
</thead>
<tbody>
#foreach (var dirDocs in Model.Docs)
{
<tr>
<td class="col-md-2">
<a asp-area="Admin" asp-controller="Docs"
asp-action="EditDirectorDocument" asp-route-
id="#dirDocs.Id">Edit</a>
<a asp-area="Admin" asp-controller="Docs"
asp-action="DeleteDirectorDocument" asp-route-
returnViewName="#returnViewName" asp-route-id="#dirDocs.Id"
onclick="return confirm('Are you sure you want to delete
this document?');">Delete</a>
</td>
<td class="col-md-2">#dirDocs.Title</td>
<td class="col-md-2">#dirDocs.Date</td>
<td class="col-md-2"><a asp-route-
id="#dirDocs.Url" target="_blank">Open</a></td>
</tr>
}
</tbody>
</table>
The file that is uploaded gets stored as a document file and is created as a url for the user to view. How do I do this in MVC. Is that set up in the controller? If so how is that done?
Not sure, but I think you just need:
Open
Instead of
<a asp-route-id="#dirDocs.Url" target="_blank">Open</a>
I assume you mean you get a URL back from the upload process that you want to display to the user so they can click on it and see the file they uploaded.
If you wanted to display some thing like that inline you could probably use an iframe whose src is set to #dirDocs.Url:
<iframe src="#dirDocs.Url"></iframe>

Navigation broken in Sitecore Page Editor during Edit related item

After updating Sitecore 6.3 to 6.6, the Main Navigation is broken in the Sitecore Page Editor when "Edit related item" is clicked.
It looks like this:
It even stays like this when closing the "Edit related item" frame.
Here is the text from that screen:
{"commands":[{"click":"chrome:common:edititem({command:\"webedit:open\"})","header":"","icon":"/~/icon/SoftwareV2/16x16/cubes_blue.png.aspx","isDivider":false,"tooltip":"Dieses Item im Content Editor bearbeiten.","type":"common"}],"contextItemUri":"sitecore://master/{78EBD797-ACA9-40BC-9ACE-961CD2296CDC}?lang=de-CH&ver=1","custom":{},"displayName":"Title","expandedDisplayName":null}KATA {"commands":[{"click":"chrome:common:edititem({command:\"webedit:open\"})","header":"","icon":"/~/icon/SoftwareV2/16x16/cubes_blue.png.aspx","isDivider":false,"tooltip":"Dieses Item im Content Editor bearbeiten.","type":"common"}],"contextItemUri":"sitecore://master/{F195AD36-86EE-4C13-883B-761E300C23AF}?lang=de-CH&ver=1","custom":{},"displayName":"Title","expandedDisplayName":null}REA {"commands":[{"click":"chrome:common:edititem({command:\"webedit:open\"})","header":"","icon":"/~/icon/SoftwareV2/16x16/cubes_blue.png.aspx","isDivider":false,"tooltip":"Dieses Item im Content Editor bearbeiten.","type":"common"}],"contextItemUri":"sitecore://master/{63438A98-FC6F-461D-89BB-7497B12FBAEF}?lang=de-CH&ver=1","custom":{},"displayName":"Title","expandedDisplayName":null}Patientensicherheit {"commands":[{"click":"chrome:common:edititem({command:\"webedit:open\"})","header":"","icon":"/~/icon/SoftwareV2/16x16/cubes_blue.png.aspx","isDivider":false,"tooltip":"Dieses Item im Content Editor bearbeiten.","type":"common"}],"contextItemUri":"sitecore://master/{FB9B0590-E933-4141-BA2B-F82C83A3343E}?lang=de-CH&ver=1","custom":{},"displayName":"Title","expandedDisplayName":null}Prozesse {"commands":[{"click":"chrome:common:edititem({command:\"webedit:open\"})","header":"","icon":"/~/icon/SoftwareV2/16x16/cubes_blue.png.aspx","isDivider":false,"tooltip":"Dieses Item im Content Editor bearbeiten.","type":"common"}],"contextItemUri":"sitecore://master/{0F1334E0-9BB7-4657-9DC4-884F6E1133C9}?lang=de-CH&ver=1","custom":{},"displayName":"Title","expandedDisplayName":null}Dokumente {"commands":[{"click":"chrome:common:edititem({command:\"webedit:open\"})","header":"","icon":"/~/icon/SoftwareV2/16x16/cubes_blue.png.aspx","isDivider":false,"tooltip":"Dieses Item im Content Editor bearbeiten.","type":"common"}],"contextItemUri":"sitecore://master/{8D18489B-B7F3-442B-9958-7D1FDBDC9010}?lang=de-CH&ver=1","custom":{},"displayName":"Title","expandedDisplayName":null}Telefonlisten
Anyone knows what this is and how I can fix it?
Thanks in advance :)
EDIT:
Code of .ascx:
<%# Control Language="C#" AutoEventWireup="true"
CodeBehind="Header.ascx.cs" Inherits="ZGKS.Intranet.WebApp.Frontend.sublayouts.Header" %>
<%# Register Src="NavLayer.ascx" TagName="NavLayer" TagPrefix="uc1" %>
<%# Register Src="~/Frontend/sublayouts/SearchBox.ascx" TagName="SearchBox" TagPrefix="ZGKSControls" %>
<div class="head">
<div class="line">
<div class="unit sizeCol">
<!-- mod NavService -->
<div class="mod modNavService skinNavServiceHome">
<div class="inner">
<div class="bd">
<ul>
<li>Home</li>
<li><span>
<asp:Literal ID="litWelcome" runat="server"></asp:Literal>
<asp:Literal ID="litUsername" runat="server"></asp:Literal></span></li>
<li class="last"><span>
<asp:Literal ID="litDate" runat="server"></asp:Literal></span></li>
</ul>
</div>
</div>
</div>
<!-- /mod NavService -->
<!-- mod NavService -->
<div class="mod modNavService">
<div class="inner">
<!-- tpl NavService-navservice -->
<div class="bd">
<ul>
<asp:Literal ID="litNaviLinks" runat="server"></asp:Literal>
</ul>
</div>
<!-- /tpl NavService-navservice -->
</div>
</div>
<!-- /mod NavService -->
<!-- mod Favourites -->
<div class="mod modFavourites">
<div class="inner">
<!-- tpl Favourites-favourites -->
<div class="hd">
<ul>
<li>Meine Favoriten
<div class="favnavcontainer">
<div class="wrap">
<div class="list">
<table>
<tbody>
<tr>
<td>
<asp:Label ID="lblFavoritesDescription" runat="server" />
</td>
</tr>
</tbody>
</table>
<table class="highlight">
<tbody>
<asp:Repeater ID="rptFavorite" runat="server" OnItemCommand="RptFavoriteItemCommand">
<ItemTemplate>
<tr class="favoritemark">
<td>
<a href="<%# Eval("Url") %>">
<%# Eval("Title") %></a>
</td>
<td class="delete">
<span>
<asp:ImageButton ToolTip="Löschen" AlternateText="Löschen" ID="btnDeleteFav" runat="server"
CommandName="delFav" CommandArgument='<%# Eval("ID") %>' ImageUrl="~/Frontend/Images/icons/clear.png" />
</span>
</td>
<td class="edit" title="Editieren">
<span></span>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
</div>
</div>
<a class="close" title="" href="#">Schliessen <span>|</span> X</a>
</div>
</li>
<li>Meine Systeme
<div class="favnavcontainer">
<div class="wrap">
<div class="list">
<table>
<tbody>
<tr>
<td>
<asp:Label ID="lblSystemDescription" runat="server" />
</td>
</tr>
</tbody>
</table>
<table class="highlight">
<tbody>
<asp:Repeater ID="rptSysteme" runat="server">
<ItemTemplate>
<tr class="">
<td>
<a target="_blank" href="<%# Eval("Url") %>">
<%# Eval("Title") %></a>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
</div>
</div>
<div class="modContent" style="padding: 0;">
<div style="margin: 10px 0; margin-left: 10px;">
<a target="_self" href='<%# MySystemLink %>' class="icon back" title="Zurück">
<span>Meine Systeme bearbeiten</span>
</a>
</div>
<a class="close" title="" href="#">Schliessen <span>|</span> X</a>
</div>
</div>
</li>
<li>Meine Alerts
<div class="favnavcontainer">
<div class="wrap">
<div class="list">
<table>
<tbody>
<tr>
<td>
<asp:Label ID="lblAlertDescription" runat="server" />
</td>
</tr>
</tbody>
</table>
<table class="highlight">
<tbody>
<asp:Repeater ID="rptAlert" runat="server" OnItemCommand="RptAlertItemCommand">
<ItemTemplate>
<tr class="alertmark">
<td>
<a href="<%# Eval("Url") %>">
<%# Eval("Title") %></a>
</td>
<td class="delete">
<span>
<asp:ImageButton ToolTip="Löschen" AlternateText="Löschen" ID="btnDeleteAlert" runat="server"
CommandName="delAlert" CommandArgument='<%# Eval("ID") %>' ImageUrl="~/Frontend/Images/icons/clear.png" />
</span>
</td>
<td class="edit" title="Editieren">
<span> </span>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
</div>
</div>
<a class="close" title="" href="#">Schliessen <span>|</span> X</a>
</div>
</li>
</ul>
</div>
<div class="bd">
</div>
<!-- /tpl Favourites-favourites -->
</div>
</div>
<!-- /mod Favourites -->
</div>
<div class="unit sizeCol lastUnit">
<div class="line">
<!-- mod Logo -->
<div class="mod modLogo">
<div class="inner">
<!-- tpl Logo-logo -->
<div class="bd">
<a href="/" title="">
<img class="screen" src="/Frontend/Images/logo.gif" width="291" height="27" alt="ZGKS"></a>
</div>
<!-- /tpl Logo-logo -->
</div>
</div>
</div>
<div class="line">
<ZGKSControls:SearchBox ID="SearchBox" runat="server" />
</div>
</div>
<div class="line">
<div class="unit size1of1">
<uc1:NavLayer ID="NavLayer1" runat="server" />
</div>
</div>
</div>
</div>
The issue is due to changes in the webedit.css stylesheet in Sitecore 6.6 from previous versions.
Make sure that /website/webedit.css is present in your inetpub folder, that you do not have it checked into your Visual Studio project, i.e it is not overwriting with a previous version of the file from your source control.

jQuery UI Tabs refreshes after button click

I have jQuery UI Tabs page:
<div class="addTheatreContainer">
<div class="addTheatreHeader">
<span class="txtLightboxTitle">ADD THEATRE</span>
</div><!--end/ .addTheatreHeader-->
<!-- Tabs -->
<div id="tabs">
<ul>
<li>
1 B.C.
</li>
<li>
2 Alberta
</li>
</ul>
<div id="#tabs-1">
<table class="table5">
<tr>
<td width="20">
<fieldset class="checkboxes">
<label class="label_check">
<input name="ctl10" type="checkbox" />
</label>
</fieldset>
</td>
<td width="40">ID</td>
<td width="120">Location</td>
<td width="120">Region</td>
<td width="120">City</td>
<td width="70">Province</td>
</tr>
</table>
</div>
<div id="#tabs-2">
<table class="table5">
<tr>
<td width="20"><fieldset class="checkboxes"><label class="label_check"><input name="ctl22" type="checkbox" /></label></fieldset></td>
<td width="40">ID</td>
<td width="120">Location</td>
<td width="120">Region</td>
<td width="120">City</td>
<td width="70">Province</td>
</tr>
</table>
</div>
</div><!--end/ #tabs-->
<div class="ButtonAlignRight">
<button id="btnAddAndCloseTheatre" runat="server" class="btnAddandCloseTheatre" >Add & Close</button>
<button id="btnAddTheatre" runat="server" class="btnAddTheatre" onclick="AddLocations()">Add</button>
<button id="btnClose" runat="server" class="btnClose">Close</button>
</div>
</div>
When I click the Add button. The whole page refreshes and I dont want it to since I am storing values in a global variable.
JS:
function AddLocations()
{
var allChecboxes = $("#tabs").tabs("options", "active").find(".checkboxes");
var allCheckedLocations = allChecboxes.find(".cbLocation").each(function () {
var checkbox = $(this);
if (checkbox.prop("checked") == true)
{
var checkboxId = checkbox.attr("id");
var locationId = parseInt(checkboxId.replace("cbLocation_", ""));
if (typeof (locationId) == "number" && isNaN(locationId) == false) {
AddedLocationsList.push(locationId);
}
//checkbox.parents(".row").fadeOut();
}
});
}
AddedLocationsList is a global variable.This function works perfectly but since the page is refreshed the variable is set back to []. I don't know why the page is being refreshed. Is there a jQuery UI callback?

Return multiple views to one ActionResult with ASP.NET MVC

What I want to achieve essentially is:
Items assigned to me
Item 1 assigned to me
Item 2 assigned to me
Item 3 assigned to me
All open items
Item 1 open to everyone
Item 2 open to everyone
Item 3 open to everyone
Item 4 open to everyone
Though from what I have experienced of MVC so far is that I would have to return the data to the view model to be able to use it in the view itself in the following manner:
<asp:Content ID="ticketsContent" ContentPlaceHolderID="MainContent" runat="server">
<div id="hdMain">
<div id="hdMainTop"><img src="images/hdMainTop.gif" alt="" /></div>
<div id="hdMainContent">
<div id="numberOfCalls">Calls assigned to you (<%=Html.ViewData("MyOpenCallsCount")%>)</div>
<div id="assignedToMe">
<div id="callHeaders">
<table id="callHeadersTbl" cellpadding="0" cellspacing="0">
<tr>
<td width="54"> </td>
<td width="270">Subject</td>
<td width="148">Logged</td>
<td width="120">Updated</td>
</tr>
</table>
</div>
<div id="greyTicketBar"> Assignee: <strong><%=Html.ViewData("UserName")%></strong></div>
<table cellpadding="0" cellspacing="0" width="643">
<% For Each aT In ViewData.Model%>
<tr>
<td width="54" class="ticketList"> </td>
<td width="270" class="ticketList"><%=Html.ActionLink(aT.Title, "Details", New With {.id = aT.CallID})%></td>
<td width="148" class="ticketList"><%=aT.loggedOn.Date.ToShortDateString%></td>
<td width="115" class="ticketList"><%=aT.updatedOn.Date.ToShortDateString%></td>
</tr>
<% Next%>
</table>
</div>
</div>
<div id="hdMainBottom"><img src="images/hdMainBottom.gif" alt="" /></div>
<div id="bigbreak">
<br />
</div>
<div id="hdMainTop"><img src="images/hdMainTop.gif" alt="" /></div>
<div id="hdMainContent">
<div id="numberOfCalls">All unsolved calls (<%=Html.ViewData("OpenCallCount")%>)</div>
<div id="unsolvedTix">
<div id="callHeaders">
<table id="callHeadersTbl" cellpadding="0" cellspacing="0">
<tr>
<td width="54"> </td>
<td width="270">Subject</td>
<td width="148">Logged</td>
<td width="58">Priority</td>
<td width="120">Updated</td>
</tr>
</table>
</div>
<div id="greyTicketBar"></div>
<table cellpadding="0" cellspacing="0" width="643">
<% For Each t As hdCall In ViewData.Model%>
<tr>
<td width="51" class="ticketList" align="center"><img src="/images/icons/<%=t.hdPriority.Priority%>.gif" /></td>
<td width="270" class="ticketList"><%=Html.ActionLink(t.Title, "Details", New With {.id = t.CallID})%></td>
<td width="148" class="ticketList"><%=t.loggedOn%></td>
<td width="58" class="ticketList"><%=t.hdPriority.Priority%></td>
<td width="115" class="ticketList"><%=t.updatedOn%></td>
</tr>
<% Next%>
</table>
</div>
</div>
<div id="hdMainBottom"><img src="images/hdMainBottom.gif" alt="" /></div>
</div>
<div id="hdSpacer"></div>
<div id="hdMenus">
<div id="browseBox">
<div id="blueTop"><img src="images/blueboxTop.gif" /></div>
<div id="blueContent">
<img src="images/browse.gif" alt="Browse" /><br /><br />
<ul>
<li> Calls for Topps<br /><br /></li>
<li> Calls for TCH<br /><br /></li>
</ul>
</div>
<div id="blueBottom"><img src="images/blueboxBottom.gif" /></div>
<br />
<div id="Dashboard">
<div id="blueTop"><img src="images/blueboxTop.gif" /></div>
<div id="blueContent"><img src="images/dashboard.gif" alt="Dashboard" /><br /><br />
<div id="storePercent"><%=Html.ViewData("OpenCallCount")%><br />
Calls Open</div>
<ul style="font-weight: bold;">
<li> Urgent: <%=Html.ViewData("UrgentCallCount")%><br /><br /></li>
<li> High: <%=Html.ViewData("HighCallCount")%><br /><br /></li>
<li> Normal: <%=Html.ViewData("NormalCallCount")%><br /><br /></li>
<li> Low: <%=Html.ViewData("LowCallCount")%></li>
</ul>
</div>
<div id="blueBottom"><img src="images/blueboxBottom.gif" /></div>
</div>
</div>
</asp:Content>
Now, the idea I have for it, even though I know it won't work would basically be:
'
' GET: /Calls/
<Authorize()> _
Function Index() As ActionResult
ViewData("OpenCallCount") = callRepository.CountOpenCalls.Count()
ViewData("UrgentCallCount") = callRepository.CountUrgentCalls.Count()
ViewData("HighCallCount") = callRepository.CountHighCalls.Count()
ViewData("NormalCallCount") = callRepository.CountNormalCalls.Count()
ViewData("LowCallCount") = callRepository.CountLowCalls.Count()
ViewData("MyOpenCallsCount") = callRepository.CountMyOpenCalls(Session("LoggedInUser")).Count()
ViewData("UserName") = Session("LoggedInUser")
Dim viewOpenCalls = callRepository.FindAllOpenCalls()
Dim viewMyOpenCalls = callRepository.FindAllMyCalls(Session("LoggedInUser"))
Return View(viewOpenCalls)
Return View(viewMyOpenCalls)
End Function
What I'm wondering is, what would be the correct way to do this? I haven't a clue as how to go about the right way, I think I at least have the theory there though, just not how to implement it.
Thanks for any help in advance.
EDIT
Based on the below comments, I have made the following code edits/additions:
Class Calls
Private _OpenCalls As hdCall
Public Property OpenCalls() As hdCall
Get
Return _OpenCalls
End Get
Set(ByVal value As hdCall)
_OpenCalls = value
End Set
End Property
Private _MyCalls As hdCall
Public Property MyCalls() As hdCall
Get
Return _MyCalls
End Get
Set(ByVal value As hdCall)
_MyCalls = value
End Set
End Property
End Class
Index() Action
'
' GET: /Calls/
<Authorize()> _
Function Index() As ActionResult
ViewData("OpenCallCount") = callRepository.CountOpenCalls.Count()
ViewData("UrgentCallCount") = callRepository.CountUrgentCalls.Count()
ViewData("HighCallCount") = callRepository.CountHighCalls.Count()
ViewData("NormalCallCount") = callRepository.CountNormalCalls.Count()
ViewData("LowCallCount") = callRepository.CountLowCalls.Count()
ViewData("MyOpenCallsCount") = callRepository.CountMyOpenCalls(Session("LoggedInUser")).Count()
ViewData("UserName") = Session("LoggedInUser")
Dim viewOpenCalls As New Calls With {.OpenCalls = callRepository.FindAllOpenCalls()}
Dim viewMyOpenCalls As New Calls With {.MyCalls = callRepository.FindAllMyCalls(Session("LoggedInUser"))}
Return View(New Calls())
End Function
Calls/Index.aspx
<%# Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Calls>" %>
<%# Import Namespace="CustomerServiceHelpdesk" %>
<asp:Content ID="ticketsHeader" ContentPlaceHolderID="TitleContent" runat="server">
Topps Customer Service Helpdesk - View All Calls
</asp:Content>
<asp:Content ID="ticketsContent" ContentPlaceHolderID="MainContent" runat="server">
<div id="hdMain">
<div id="hdMainTop"><img src="images/hdMainTop.gif" alt="" /></div>
<div id="hdMainContent">
<div id="numberOfCalls">Calls assigned to you (<%=Html.ViewData("MyOpenCallsCount")%>)</div>
<div id="assignedToMe">
<div id="callHeaders">
<table id="callHeadersTbl" cellpadding="0" cellspacing="0">
<tr>
<td width="54"> </td>
<td width="270">Subject</td>
<td width="148">Logged</td>
<td width="120">Updated</td>
</tr>
</table>
</div>
<div id="greyTicketBar"> Assignee: <strong><%=Html.ViewData("UserName")%></strong></div>
<table cellpadding="0" cellspacing="0" width="643">
<% For Each aT In Model.MyCalls%>
<tr>
<td width="54" class="ticketList"> </td>
<td width="270" class="ticketList"><%=Html.ActionLink(aT.Title, "Details", New With {.id = aT.CallID})%></td>
<td width="148" class="ticketList"><%=aT.loggedOn.Date.ToShortDateString%></td>
<td width="115" class="ticketList"><%=aT.updatedOn.Date.ToShortDateString%></td>
</tr>
<% Next%>
</table>
</div>
</div>
<div id="hdMainBottom"><img src="images/hdMainBottom.gif" alt="" /></div>
<div id="bigbreak">
<br />
</div>
<div id="hdMainTop"><img src="images/hdMainTop.gif" alt="" /></div>
<div id="hdMainContent">
<div id="numberOfCalls">All unsolved calls (<%=Html.ViewData("OpenCallCount")%>)</div>
<div id="unsolvedTix">
<div id="callHeaders">
<table id="callHeadersTbl" cellpadding="0" cellspacing="0">
<tr>
<td width="54"> </td>
<td width="270">Subject</td>
<td width="148">Logged</td>
<td width="58">Priority</td>
<td width="120">Updated</td>
</tr>
</table>
</div>
<div id="greyTicketBar"></div>
<table cellpadding="0" cellspacing="0" width="643">
<% For Each t As hdCall In Model.OpenCalls%>
<tr>
<td width="51" class="ticketList" align="center"><img src="/images/icons/<%=t.hdPriority.Priority%>.gif" /></td>
<td width="270" class="ticketList"><%=Html.ActionLink(t.Title, "Details", New With {.id = t.CallID})%></td>
<td width="148" class="ticketList"><%=t.loggedOn%></td>
<td width="58" class="ticketList"><%=t.hdPriority.Priority%></td>
<td width="115" class="ticketList"><%=t.updatedOn%></td>
</tr>
<% Next%>
</table>
</div>
</div>
<div id="hdMainBottom"><img src="images/hdMainBottom.gif" alt="" /></div>
</div>
<div id="hdSpacer"></div>
<div id="hdMenus">
<div id="browseBox">
<div id="blueTop"><img src="images/blueboxTop.gif" /></div>
<div id="blueContent">
<img src="images/browse.gif" alt="Browse" /><br /><br />
<ul>
<li> Calls for Topps<br /><br /></li>
<li> Calls for TCH<br /><br /></li>
</ul>
</div>
<div id="blueBottom"><img src="images/blueboxBottom.gif" /></div>
<br />
<div id="Dashboard">
<div id="blueTop"><img src="images/blueboxTop.gif" /></div>
<div id="blueContent"><img src="images/dashboard.gif" alt="Dashboard" /><br /><br />
<div id="storePercent"><%=Html.ViewData("OpenCallCount")%><br />
Calls Open</div>
<ul style="font-weight: bold;">
<li> Urgent: <%=Html.ViewData("UrgentCallCount")%><br /><br /></li>
<li> High: <%=Html.ViewData("HighCallCount")%><br /><br /></li>
<li> Normal: <%=Html.ViewData("NormalCallCount")%><br /><br /></li>
<li> Low: <%=Html.ViewData("LowCallCount")%></li>
</ul>
</div>
<div id="blueBottom"><img src="images/blueboxBottom.gif" /></div>
</div>
</div>
</asp:Content>
However, the line <%=Html.ViewData("MyOpenCallsCount")%> gives me an End of Statement expected error.
Also, I did get it to compile once, but I got the error Unable to cast object of type 'System.Data.Linq.DataQuery1[CustomerServiceHelpdesk.hdCall]' to type 'CustomerServiceHelpdesk.hdCall'. from the line Dim viewOpenCalls As New Calls With {.OpenCalls = callRepository.FindAllOpenCalls()}
Where did I go wrong?
I'm a bit of noob when it comes to things like this, so any help is much appreciated.
Well, you can't return two values from a function, if that's what you are trying to do (the title suggests that's what you want).
Plus that's not how http works anyway. There's always just one response for a request.
But if you are trying to send both your viewOpenCalls and viewMyOpenCalls objects to one view, then you can do that with making your view have a model that'll hold both of them.
Like this :
//My VB is a bit rusty so I'm writing this in C#
class Calls {
public yourDataType OpenCalls { get; set; }
public yourDataType MyCalls { get; set; }
}
In your controller action :
return View(new Calls { OpenCalls = viewOpenCalls, MyCalls = viewMyOpenCalls })
//I gues in VB it would be like this :
Dim viewOpenCalls = callRepository.FindAllOpenCalls()
Dim viewMyOpenCalls = callRepository.FindAllMyCalls(Session("LoggedInUser"))
Return View(New Calls _
With {.OpenCalls = viewOpenCalls, .MyCalls = viewMyOpenCalls})
In your view make sure it's model is type of the Calls class.
<%# Page Inherits="System.Web.Mvc.ViewPage<Calls>" %>
And now you can access the properties with <%=Model.OpenCalls %> and <%=Model.MyCalls %>
Once I'd worked out the correct way of doing it (a little while a go now) I got it working.
For reference, this is the way it should be done:
Public Class TheCalls
Private _OpenCalls As IQueryable(Of hdCall)
Public Property OpenCalls() As IQueryable(Of hdCall)
Get
Return _OpenCalls
End Get
Set(ByVal value As IQueryable(Of hdCall))
_OpenCalls = value
End Set
End Property
Private _AssignedCalls As IQueryable(Of hdCall)
Public Property AssignedCalls() As IQueryable(Of hdCall)
Get
Return _AssignedCalls
End Get
Set(ByVal value As IQueryable(Of hdCall))
_AssignedCalls = value
End Set
End Property
End Class
1) Create a ViewData class. This is just a POCO class with properties defined for each data item you want to show on the view (e.g. OpenCallCount)
2) Create a strongly typed view that uses this ViewData class.
3) Pass a new instance of your ViewData class, with the properties set, to your view.
This will help you avoid using magic strings everywhere (e.g. ViewData("OpenCallCount") = ... becomes myViewDataClass.OpenCallCount = ...)
You could probably tidy up the view by using two partial view classes, or making it slightly more generic, but it will do the job at the moment.

Resources