View/open file url - asp.net-mvc

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>

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>

MVC5 Bootstrap collapsible with dynamic class

I am having my view bound to datatable as follows
#{int i = 1;}
#foreach (var item in Model.Rows)
{
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading bg-info">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse#(i)">
<div class="col-lg-3">
<img style="width:50px" class="float-left p-l-5" src="https://organicthemes.com/demo/profile/files/2012/12/profile_img.png" /> <div class="float-left p-l-10">
<h4 class="m-t-0">#item["First_Name"]</h4>
<p><b>##item["Employee_Code"]</b></p>
</div>
</div>
<div class="col-lg-4">
<h4 class="m-t-0">#item["Leave_Description"]: #item["No_Of_Days"] days - <span class="blue_heading">#item["Start_date"]</span></h4>
<h4 class="m-t-0">#item["Leave_Purpose"]</h4>
</div>
<div class="col-lg-4">
</div>
</a>
</div>
<div id="collapse#(i)" class="panel-collapse collapse">
<div class="panel-body">
<div class="center_table">
<div class="border_table">
<table class="table table-hover table-expandable table-striped">
<tr>
<td>
Leave Type: #item["Leave_Description"]
</td>
<td>
Days : #item["No_Of_Days"]
</td>
</tr>
<tr>
<td>
From : #item["Start_Date"]
</td>
<td>
To : #item["End_Date"]
</td>
</tr>
<tr>
<td colspan="2">Reason : #item["Leave_Purpose"]</td>
</tr>
</table>
</div>
<div class="clearfix"></div>
<div class="well text-center p-10"><button type="button" class="btn btn-default">Accept Grant</button> <button type="button" class="btn btn-default">Reject</button></div>
</div>
</div>
</div>
</div>
</div>
i++;
}
I am getting the required output but when clicking on first row the second row is also showing as collapsed. My scenario is when there are multiple rows on clicking a particular row other rows collapse should be hidden.
Can someone tell what change do I need to achieve the scenario?
Can you try
i=i+1;
Sometime foreach confuses with ++ operator
Also you can try collapse-#i instead of #collapse#(i)

HttpPostedFileBase is coming null

below is the code in my View
#using ClaimBuildMVC.Models
#model IEnumerable<Asset>
#{
ViewBag.Title = "AssetsPage";
Layout = "~/Views/Shared/_SuperAdminLayout.cshtml";
}
<script type="text/javascript">
</script>
#using (Html.BeginForm("AssetsPage", "SuperAdmin", FormMethod.Post,new{enctype = "multipart/form-data"}))
{
<div class="Content-inner-pages">
<div class="TopHeading TopHeading2">
<h2>Assets</h2>
<a class="CreateBtn AssetsBtn" href="Javascript:void(0);" onclick="javascript:$('#hdnIsNew').val('1')">Add Asset</a>
<div class="clearfix"></div>
</div>
<input type="hidden" id="hdnIsNew" value="1" />
<input type="hidden" id="hdnRecId" />
<!-- Slide Popup panel -->
<div class="cd-panel from-right AddAssetForm">
<header class="cd-panel-header">
<h3>Add Asset</h3>
Close
</header>
<div class="cd-panel-container">
<div class="cd-panel-content">
<div class="form-horizontal form-details popup-box">
<div class="form-group">
<label class="col-md-5 control-label">
Asset Title
</label>
<div class="col-md-7">
<input type="text" id="txtTitle" name="txtTitle" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-md-5 control-label">Description</label>
<div class="col-md-7">
<textarea id="txtDesc" class="form-control" cols="5" rows="5"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-5 control-label">Attachment</label>
<div class="col-md-7">
<input type="file" id="file" class="custom-file-input">
</div>
</div>
<div class="form-group">
<div class="col-md-7 col-md-offset-5">
<input type="submit" value="Save" name="actionType" class="btn-class btn-success">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="box">
<div class="box-content Custom-DataTable">
<table id="AdministationAssets" class="table table-hover dt-responsive CustomDatable AdministationAssetsTable" cellspacing="0" width="100%">
<thead>
<tr>
<th style="width:5%;">Assets</th>
<th style="width:15%;">
#Html.DisplayNameFor(model =>model.Title)
</th>
<th style="width:50%;">
#Html.DisplayNameFor(model =>model.Description)
</th>
<th style="width:8%;">Options</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td></td>
<td>
#Html.DisplayFor(modelItem => item.Title)
</td>
<td>
#Html.DisplayFor(modelItem =>item.Description)
</td>
<td>
#Html.ActionLink("Edit", "AddEditRecord", new{ id = item.ID }, new { #class = "ActionEdit AssetEdit", onclick ="javascript:GetEditDetails(" + item.ID + ");" })
#Html.ActionLink("Delete", "AssetDelete", new{ id = item.ID }, new { #class = "ActionDelete", onclick = "return confirm('Are You Sure delete this record?');", })
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
and below is my controller that what i want to call when click on save button but 'img' is coming as null and after searching in google i found that to add #using(Html.BeginForm()) but still it is coming as null
[HttpPost]
public ActionResult AssetsPage(Asset ast, HttpPostedFileBase file)
{
using (GenericUnitOfWork gc = new GenericUnitOfWork())
{
if (HttpContext.Request.Files.Count > 0)
{
ast.ContainerName = "reports";
ast.BlobName = HttpContext.Request.Files[0].FileName;
ast.BlobUrl = BlobUtilities.CreateBlob(ast.ContainerName, ast.BlobName, null, GetStream(HttpContext.Request.Files[0].FileName));
ast.FileName = HttpContext.Request.Files[0].FileName;
}
gc.GetRepoInstance<Asset>().Add(ast);
gc.SaveChanges();
}
return RedirectToAction("AssetsPage");
}
Not able to find the solution. Please help or give some reference if possible.
Asp.Net MVC default model binding works with name attribute, So add name="file" attribute with input type="file" as shown :-
<input type="file" name="file" id="file" class="custom-file-input">

Display hidden row in asp.net mvc grid

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)

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