Item.Object.Property not showing in .htmlcs (#Html.DisplayFor) - c#

I am currently working on a project where I want to show a column of a related record (form a sql database). For some of my table this works perfeclty fine, altough for one of them it does not. As shown below, there is no error and the record is filled in with the correct data, but it does not show up correclty. Can anyone help me with this? I tried updating my database already.
<table id="coaches">
<thead>
<tr>
<th>
</th>
<th>
#Html.DisplayNameFor(model => model.Picture)
</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model) {
<tr>
<td>
<img src=#Html.DisplayFor(modelItem => item.Picture) class="person">
</td>
<td>
<div style="padding-left:10px">
<div class="name">#Html.DisplayFor(modelItem => item.Organization.Name)Should be here</div>
<div class="natclub">
<img src="https://dalto.nl/wp-content/uploads/2018/08/dalto-logo.png" class="emblem">
<br>
<img src="https://cdn.countryflags.com/thumbs/netherlands/flag-400.png" class="flag">
</div>
</div>
</td>
</tr>
}
</tbody>
</table>
Organization Table
Coaches table
Page in question
Thanks in advance!
I tried to release a new update of the database using the PM Console, but nothing changed.

Related

Index page with datatable took about 6-7 seconds before showing search box

I have a simple index page. When I load the page with only 500 records, the search box shows up straight away. But with 12k records, it take some time. Is there a way I can show a LOADING message, and after the search box is loaded, the LOADING message disappear.
This is the Index.cshtml
#model IEnumerable<BSMV2.Models.StoAppnOrgView>
<h2>LIST OF STONES</h2>
<table id="applicationTable" class="table table-striped table-bordered">
<thead>
<tr>
<th>
#Html.DisplayNameFor(model => model.Stone)
</th>
<th>
#Html.DisplayNameFor(model => model.Applicant)
</th>
<th>
#Html.DisplayNameFor(model => model.Org)
</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.Stone)
</td>
<td>
#Html.DisplayFor(modelItem => item.Applicant)
</td>
<td>
{#Html.DisplayFor(modelItem => item.Org)
</td>
<td>
#Html.ActionLink("Details", "Details", new { Id = item.Id })
</td>
</tr>
}
</tbody>
#section Scripts{
<script type="text/javascript">
$(document).ready(function () {
$('#applicationTable').DataTable();
});
</script>}
Here is the controller
public async Task<ActionResult> Index()
{
return View(await db.StoAppnOrgViewObj.ToListAsync());
}
Here is the Search box.
You should not be loading all 12k data on the UI. Instead use server side paging which will give the user similar experience but performance wise will be faster. The system will not be slower. The data will grow over the time and you will have to shift to server side logic anyways in the future.
You can also use the progress indicator that comes with datatable. All you have to do the followings:
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "../server_side/scripts/test.php"
} );
For the server side logic, you can follow the codes from here.

How can I filter data in a Razor view with a dropdown

Hello I'm new to MVC and I'm trying to do a filtering for my index page, I want to be able to filter the graduation Status.
So when I go into the index I will see every status and I want to filter for example only the person with the graduated Status or the Pass/failed Status
Thank you in advance!
Index Page
Controller:
var graduates = db.Graduated_Students;
return View(graduates.ToList());
View:
<div class="content-body">
<div class="row">
<form action="#" method="post">
<div class="col-xs-12 col-sm-9 col-md-12">
<table class="table">
<tr>
<th>
#Resource.FirstName
</th>
<th>
#Resource.LastName
</th>
<th>
#Resource.CohortNumber
</th>
<th>
Placements
</th>
<th>
#Resource.GraduationStatus
</th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem =>
item.FirstName)
</td>
<td>
#Html.DisplayFor(modelItem =>
item.LastName)
</td>
<td>
#Html.DisplayFor(modelItem => item.Name)
</td>
<td>
#Html.DisplayFor(modelItem =>
item.PartnerName)
</td>
<td>
#Html.DisplayFor(modelItem =>
item.GraduationStatus)
</td>
You could use linq in the View to filter the data
In the View
#foreach (var item in Model.Where(t=> t.GraduationStatus == <the graduation status selected in the dropdown> );
This approach Gets all the data from the database and then performs the filtering
That approach would work however a better approach would be to send the Selected GraduationStatus to the controller as a parameter and then perform the filtering directly on the db variable
In the Controller
public IActionResult GeStudents(GraduationStatus selectedGraduationStatus)
{
var graduates = db.Graduated_Students.Where(t=> t.GraduationStatus == selectedGraduationStatus);
return View(graduates.ToList());
}
This way you don't get all of the students from the database but only the ones which match the filter

how to update a raw within a partial view in MVC C#

i have a web application where i need to update the rows of a table one by one inside a partial view. the problem i'm facing now is how can i insert the update inside the partial view method in the controller. i'm using visual studio 2013 toad for oracle
The partial view
<table>
<thead>
<tr>
<th style="display:none;"> ProID </th>
<th> Requeser Name </th>
<th> Project Name </th>
<th> Supervisor Name </th>
<th> Description </th>
<th> Start Date </th>
<th> Due Date </th>
<th> Status </th>
<th> Done </th>
</tr>
</thead>
<tbody>
<tr>
#foreach (var items in Model)
{
<td>#items.USERID</td>
}
<td>
<input type="text" id="txt_pname" />
</td>
<td>
<input type="text" id="txt_sname" />
</td>
<td>
<input type="text" id="txt_dname" />
</td>
<td> <input name="text_stdate" id="iDate" class="form-control" readonly>
<span class="input-group-btn">
<button class="btn default" type="button"><i class="fa fa-calendar"></i></button>
</span></td>
<td>
<input name="text_dudate" id="iDate" class="form-control" readonly>
<span class="input-group-btn">
<button class="btn default" type="button"><i class="fa fa-calendar"></i></button>
</span>
</td>
<td>
<input type="text" id="txt_dname" />
</td>
<td>
<select id="txt_stat">
<option>Pending</option>
<option>Open</option>
<option>Close</option>
<option>Cancle</option>
</select>
</td>
</tr>
#foreach (var items in Model)
{
<td>
<a onclick="update_Row('#items.PROJECTT', '#items.IDP');" class="edit" href="#"> Done </a>
</td>
}
</table>
<table class="" id="sample_editable_1">
<thead>
<tr>
<th style="display:none;"> ProID </th>
<th> Requeser Name </th>
<th> Project Name </th>
<th> Supervisor Name </th>
<th> Description </th>
<th> Start Date </th>
<th> Due Date </th>
<th> Status </th>
<th> Edit </th>
</tr>
</thead>
<tbody>
#foreach (var items in Model)
{
<tr>
<td style="display:none;"> #items.IDP</td>
<td>#items.USERID</td>
<td>#items.PROJECTT</td>
<td>#items.PROJSUP</td>
<td>#items.PROJDES</td>
<td>#items.STARTDT</td>
<td>#items.DUEDT</td>
<td>#items.SCONDITION</td>
<td>
<a onclick="update_Row('#items.PROJECTT', '#items.IDP');" class="edit" href="#"> Edit </a>
</td>
</tr>
}
</tbody>
</table>
the controller
public ActionResult viewstat(string id)
{
List<mdlProject> itemList = new List<mdlProject>();
try
{
dbconn.openConnection();
strSQL = #"select ID,PROJTTL,PROJSVSOR,PROJDES,STARTDT,DUEDT,USERID,S_CONDITION from
PR_TBLPROJECT
inner join PR_TBLSTATUS on pr_tblstatus.s_id=PR_TBLPROJECT.id
where PR_TBLPROJECT.id=:id";
cmd = new OracleCommand(strSQL, dbconn.DbConn);
cmd.Parameters.Add("PROJTTL", OracleDbType.Varchar2, id, ParameterDirection.Input);
OracleDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
itemList.Add(new mdlProject
{
PROJECTT = dr["PROJTTL"].ToString(),
PROJSUP = dr["PROJSVSOR"].ToString(),
PROJDES = dr["PROJDES"].ToString(),
STARTDT = Convert.ToDateTime(dr["STARTDT"].ToString()).ToString("dd-MM-yyyy"),
DUEDT = Convert.ToDateTime(dr["DUEDT"].ToString()).ToString("dd-MM-yyyy"),
USERID = dr["USERID"].ToString(),
SCONDITION = dr["S_condition"].ToString(),
IDP = dr["ID"].ToString(),
//SID = dr["S_ID"].ToString(),
ACTV = "",
});
}
}
dr.Dispose();
cmd.Dispose();
}
finally
{
dbconn.closeConnection();
}
return PartialView(itemList);
}
Not sure what exact error you are getting but approach will be On click of each anchor tag, call a javascript method and from that javascipt method send a ajax request to update the row and then call your partial view method viewstat to refresh the table.

Center Checkbox on its label in a Table in MVC

In my Project I am working on a few index views that only have a few fields. When their are few fields in a table the label and the checkbox below them never line up. As one example, in the code below the Active field is a checkbox and it is not under its label. How can I get it so the checkbox is centered on its label?
<table class="table">
<tr>
<th>
#Html.DisplayNameFor(model => model.BranchName)
</th>
<th>
#Html.DisplayNameFor(model => model.Active)
</th>
<th></th>
</tr>
#foreach (var item in Model.OrderByDescending(m => m.Active).ThenBy(m => m.BranchName))
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.BranchName)
</td>
<td>
#Html.DisplayFor(modelItem => item.Active)
</td>
<td>
#Html.ActionLink("Edit", "EditBranch", new { id=item.BranchId })
</td>
</tr>
}
</table>
Here is a pic to see how ugly it looks:
Add css to the column, via colspan or direct on td or th
<td style="text-align: center">
OR
style="float:left"
Otherwise encapsulate the #Html.DisplayFor in a div with that style.
Finally don't have the css inline and move to the style.css file.

Razor get value of input HTML bounded by foreach

I have one following table html, the data of rows in the table is looped by foreach.
Can I use Razor to get the value of each row into a List or an array in C#?
My C# code Razor (I tried this so far)
#{
var l = new List<string>();
l.Add(#<input id="updated_value2" data-bind="value:value,visible:isEditing()" />);
}
Here's my table
<table class="table table-hover">
<tbody data-bind="foreach: $root.mapJsons(parameters())">
<tr class="data-hover">
<td>
<strong>
<span data-bind="text:key" />
</strong>
</td>
<td>
#*display label and input for dictionary<value> false DIS true APP*#
<input id="updated_value" data-bind="value:value,visible:isEditing()" />
<label id="display_value" data-bind="text:value,visible:!isEditing()" />
</td>
</tr>
</tbody>
<thead>
<tr>
<th style="width: 30%">
Name
</th>
<th style="width: 30%">
Value
</th>
<th></th>
</tr>
</thead>
</table>
Your foreach loop is being executed client-side (looks like a KnockoutJS binding?) rather than server-side, so any Razor code you embed in the table is only going to be called once as it's rendered by the server. So the answer is no, you cannot populate a server-side list with this particular foreach loop.

Categories