Renderpartial or renderaction - asp.net-mvc-2

have an action that generates active vacancies. The code is below;
public ViewResult OpenVacancies()
{
var openvacancies = db.GetActiveVacancies();
return View(openvacancies);
}
I want to use this list on several pages so i guess the best thing to use is html.renderaction (please correct me if i am wrong here).
Please note that the view and .ascx control are in an Area.
I then created a view by right clicking inside the action and create a .ascx and a strongly typed view of Vacancy. I chose a view content of "List".
I then added this line to the required page;
Please note that the view and .ascx control are in an Area.
The error i got is;
The type or namespace name 'Vacancy' could not be found (are you missing a using directive or an assembly reference?)
the .ascx code is below;
>" %>
<table>
<tr>
<th></th>
<th>
VacancyID
</th>
<th>
JobTitle
</th>
<th>
PositionID
</th>
<th>
LocationID
</th>
<th>
JobDescription
</th>
<th>
JobConditions
</th>
<th>
Qualifications
</th>
<th>
RequiredSkills
</th>
<th>
Certifications
</th>
<th>
AdvertDate
</th>
<th>
AdvertExpiryDate
</th>
<th>
Status
</th>
<th>
StaffLevel
</th>
<th>
LineManagerEmail
</th>
<th>
ApprovalFlag
</th>
<th>
RequisitionDate
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%= Html.ActionLink("Edit", "Edit", new { id=item.VacancyID }) %> |
<%= Html.ActionLink("Details", "Details", new { id=item.VacancyID })%> |
<%= Html.ActionLink("Delete", "Delete", new { id=item.VacancyID })%>
</td>
<td>
<%= Html.Encode(item.VacancyID) %>
</td>
<td>
<%= Html.Encode(item.JobTitle) %>
</td>
<td>
<%= Html.Encode(item.PositionID) %>
</td>
<td>
<%= Html.Encode(item.LocationID) %>
</td>
<td>
<%= Html.Encode(item.JobDescription) %>
</td>
<td>
<%= Html.Encode(item.JobConditions) %>
</td>
<td>
<%= Html.Encode(item.Qualifications) %>
</td>
<td>
<%= Html.Encode(item.RequiredSkills) %>
</td>
<td>
<%= Html.Encode(item.Certifications) %>
</td>
<td>
<%= Html.Encode(String.Format("{0:g}", item.AdvertDate)) %>
</td>
<td>
<%= Html.Encode(String.Format("{0:g}", item.AdvertExpiryDate)) %>
</td>
<td>
<%= Html.Encode(item.Status) %>
</td>
<td>
<%= Html.Encode(item.StaffLevel) %>
</td>
<td>
<%= Html.Encode(item.LineManagerEmail) %>
</td>
<td>
<%= Html.Encode(item.ApprovalFlag) %>
</td>
<td>
<%= Html.Encode(String.Format("{0:g}", item.RequisitionDate)) %>
</td>
</tr>
<% } %>
</table>
<p>
<%= Html.ActionLink("Create New", "Create") %>
</p>

First, if you simply want to reuse your view on multiple pages, you should be using a shared partial view (place it in the Shared folder) with <% Html.RenderPartial("OpenVacancies"); %>.
Second, based on your code snippet, your partial view doesn't appear to be strongly typed. Instead of
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
you will want something like this:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Vacancy>>" %>

Related

Passing data from table to Modal Table

I have two tables for my inventory first is the Item List then the Item Info
I bind the Item List to a HTML Table the add a button for each row the purpose of the button is to show the Item Info or table via modal
I have already done the table and modal design but i cant get or pass the Item ID for my Item List to my modal
can anyone help me i'm kind a new in HTML (noob hir :3)
<thead>
<tr>
<th class="text-center">Item ID</th>
<th class="text-center">Particular</th>
</tr>
</thead>
<tbody class="searchable">
<% List<Inventory.MODEL.adminView>x = new List
<Inventory.MODEL.adminView>(); Inventory.BAL.ItemBAL z = new Inventory.BAL.ItemBAL(); x = z.getAdminView().ToList(); foreach (var item in x) {%>
<tr>
<td>
<%=i tem.ID %>
</td>
<td>
<%=i tem.Particulars %>
</td>
<%}%>
<td class="text-center">
<span class='glyphicon glyphicon-info-sign'></span>
</td>
</tr>
<%} %>
</tbody>
</table>
</div>
</div>
<div id="Modal" class="modal fade">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Item Inventory</h4>
</div>
<div class="modal-body">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th class="text-center">Item ID</th>
<th class="text-center">Total Quantity</th>
</tr>
</thead>
<tbody>
<% iteminvents(); %>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
that's my code, anyone can advice or can help me ?
Pass this in myFunction() as argument , As myFunction(this)
and inside function you can get ItemId as below. I have used jquery here.
function myFunction(sender)
{
var CurrentRow=$(sender).closest("tr");
var ItemId=$("td:eq(0)",$(CurrentRow)).html(); // Can Trim also if needed
}

sahi and table operations

For a given table, I'd like to get the below
total number of rows
able to iterate over by row and column
using the Java Driver. I tried the option mentioned here with no luck.
Below is the HTML for table
<div id="hawkMessageCodeTable" class="ui-datatable ui-widget">
<table>
<thead>
<tr>
<th id="hawkMessageCodeTable:j_idt49" class="ui-state-default">
<div class="ui-dt-c">
<span>Code</span>
</div>
</th>
<th id="hawkMessageCodeTable:j_idt51" class="ui-state-default">
<div class="ui-dt-c">
<span>Message</span>
</div>
</th>
</tr>
</thead>
<tbody id="hawkMessageCodeTable_data" class="ui-datatable-data ui-widget-content">
<tr data-ri="0" class="ui-widget-content ui-datatable-even">
<td>
<div class="ui-dt-c">
9005
</div>
</td>
<td>
<div class="ui-dt-c">
Initial Fraud Alert on File
</div>
</td>
</tr>
<tr data-ri="1" class="ui-widget-content ui-datatable-odd">
<td>
<div class="ui-dt-c">
9003
</div>
</td>
<td>
<div class="ui-dt-c">
Security Alert or consumer statement on file relates to true name fraud or credit fraud
</div>
</td>
</tr>
<tr data-ri="2" class="ui-widget-content ui-datatable-even">
<td>
<div class="ui-dt-c">
2501
</div>
</td>
<td>
<div class="ui-dt-c">
Input/File (Current/Previous) Address Has Been Used (#) Times In The Last (30,60,90) Days On Different Inquiries
</div>
</td>
</tr>
<tr data-ri="3" class="ui-widget-content ui-datatable-odd">
<td>
<div class="ui-dt-c">
9004
</div>
</td>
<td>
<div class="ui-dt-c">
Active Duty Alert on File
</div>
</td>
</tr>
</tbody>
</table>
</div>
I have implemented a similar function with sahi for ruby. To answer your questions:
rowLen = table.fetch("rows.length").to_i
Loop through all the cells with:
#browser.cell(table,rowIndex,colIndex).exists?()
You can find the corresponding api for sahi java

CanJS EJS table - rows appearing above the table

I am new to CanJS and was trying to learn via tutorials.. Once place where I got stuck was when I converted the todo tutorial code to use table instead of UL/LI combination.
May be I am making some very small mistake.. but could not find out the same for last 3 days.. Can someone help out?
The jsFiddle for the short version of todo tutorial (which now uses tables) is here where you can see the problems.
The crux of the code from ejs is here..
<script type='text/ejs' id='todosEjs'>
<table border="1">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>status</th>
</tr>
</thead>
<tbody>
<!-- bind to changes in the todo list -->
<% this.each(function( todo ) { %>
<!-- add the todo to the element's data -->
<tr <%= (el) -> el.data('todo',todo) %>>
<td>
<input type="checkbox" <%= todo.attr('complete') ? 'checked' : '' %>>
</td>
<td><%= todo.attr('name') %></td>
<td><%= todo.attr('id') %></td>
</tr>
<% }) %>
</tbody>
</table>
</script>
Looking forward towards helping hands :-)
UPDATE: This was the result of a bug which is now fixed
It looks as if the comments are the problem here. Removing them makes it work, see the updated Fiddle:
<table border="1">
<tr>
<th>id</th>
<th>name</th>
<th>status</th>
</tr>
<% this.each(function( todo ) { %>
<tr <%= (el) -> el.data('todo',todo) %>>
<td>
<input type="checkbox" <%= todo.attr('complete') ? 'checked' : '' %>>
</td>
<td><%= todo.attr('name') %></td>
<td><%= todo.attr('id') %></td>
</tr>
<% }) %>

Linq query Group By error in ASP.NET MVC 2

I am having a bit of a struggle using linq and returning a list while trying to group.
In my view, I have the following:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcApplication1.Models.Log>>" %>
<table>
<tr>
<th>
ID
</th>
<th>
User
</th>
<th>
NumberDialed
</th>
<th>
Date
</th>
<th>
Time
</th>
<th> </th>
</tr>
<% foreach (var item in Model)
{ %>
<tr>
<td>
<%: item.ID %>
</td>
<td>
<%: item.UserName %>
</td>
<td>
<%: item.NumberDialed %>
</td>
<td>
<%: item.Date %>
</td>
<td>
<%: item.Time %>
<%} %>
</td>
</table>
and in my controller I have:
public ActionResult Tenant()
{
LogEntities db = new LogEntities();
var s = from logs in db.Logs
group logs by logs.UserName;
return View(s.ToList());
}
when I do a normal select it works:
public ActionResult Tenant()
{
using (LogEntities db = new LogEntities())
{
var s = from logs in db.Logs
orderby logs.UserName
select logs;
return View(s.ToList());
}
}
Why is using Group By not working and why it is so different? I want to be able to display the data by groups. How do I accomplish this?
Thanks :)
I think that in order to do a group you need to specify into what you need it to be grouped
var s = (from logs in db.Logs
group logs by logs.UserName into us
select us).ToList();
Then us.Key gives you the username by which it is grouped and us gives all the items that are grouped by this username.
Then you can do:
foreach(var userGroup in s){
var userName = us.Key;
var logs = us.ToList();
}

How can I strongly-type in what my View inherits from?

CS0234: The type or namespace name 'Helpers' does not exist in the namespace 'UTEPSA' (are you missing an assembly reference?)
Here is the view code that's trying to inherit:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<UTEPSA.Helpers.PaginatedList<Area>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Index
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Index</h2>
<table>
<tr>
<th></th>
<th>
ID
</th>
<th>
IDJefe
</th>
<th>
Nombre
</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%: Html.ActionLink("Edit", "Edit", new { id=item.ID }) %> |
<%: Html.ActionLink("Details", "Details", new { id=item.ID })%> |
<%: Html.ActionLink("Delete", "Delete", new { id=item.ID })%>
</td>
<td>
<%: item.ID %>
</td>
<td>
<%: item.IDJefe %>
</td>
<td>
<%: item.Nombre %>
</td>
</tr>
<% } %>
</table>
<p>
<%: Html.ActionLink("Create New", "Create") %>
</p>
</asp:Content>
And a screenshot of my solution:
How can I correctly reference my PaginatedList? Since the view is inheriting from my thing I want, I'd expect to have strongly typed Model to work with. But intellisense isn't working so somethings wrong.
You must add the assembly to both the Project Reference list as well as the <system.web><compilation><assemblies> section of web.config.