if statement fails when true - c#

This piece of code is failing when I build my project. THe if statement has to check if ParkingLot is true. I thought the way to do that was the following code:
<th class="small-12 large-6 columns last">
<table>
<tr>
<th width="300">
<p class="text-left small-text-left">
#if(Model.Point.Store.JsonDynamic.En.Motel.ParkingLot == True)
{
<span>Possibility for parking</span><br>
}
</p>
</th>
<th class="expander"></th>
</tr>
</table>
</th>
But I get this error:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot
implicitly convert type ''Newtonsoft.Json.Linq.JValue'' to ''bool''.
An explicit conversion exists (are you missing a cast?)
Can anybody see what I am doing wrong here?

Try this
<th class="small-12 large-6 columns last">
<table>
<tr>
<th width="300">
<p class="text-left small-text-left">
#(if((bool)Model.Point.Store.JsonDynamic.En.Motel.ParkingLot == True){<span>Possibility for parking</span><br>})
</p>
</th>
<th class="expander"></th>
</tr>
</table>
</th>

Related

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

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.

Get object inside partial View

Friends,
I have a View page called "OtherDatas.cshtml" and i need to render a PartialView inside her. So, to make this, i need to check if the object inside partialView is null or not. If not, the partialView Appears. How can i get the object inside the partialView? Here is my code:
OtherDatas.cshtml:
<div class="table-responsive">
#{
if (//I need to check the object inside ){
Html.Partial("~/Views/Outrosdados/Search.cshtml");
}
else
{
<table class="table table-striped">
<tr>
<th style="min-width:130px;">Mês</th>
<th style="min-width:80px;">Amortização</th>
<th style="min-width:100px;">Recebimento do Mês</th>
<th style="min-width:100px;">Atraso</th>
<th style="min-width:100px;">DAMP3</th>
</tr>
</table>
}
}
</div>
PartialView Search.html:
#model TB_DADOS_MANUAIS
#using EixoX.Html;
#using Gestão.Models;
#using System.Globalization;
#{
List<TB_OUTROS_DADOS> od = (List<TB_OUTROS_DADOS>)ViewData["outrosDados"];
Bootstrap3Presenter<TB_OUTROS_DADOS> presenter =
Bootstrap3Presenter<TB_OUTROS_DADOS>.GetInstance("pt-BR");
ViewBag.Title = "Outros Dados";
}
<table class="table table-striped">
<tr>
<th style="min-width:130px;">Mês</th>
<th style="min-width:80px;">Amortização</th>
<th style="min-width:100px;">Recebimento do Mês</th>
<th style="min-width:100px;">Atraso</th>
<th style="min-width:100px;">DAMP3</th>
</tr>
#foreach (TB_OUTROS_DADOS dados in od){
<tr>
<td>#dados.DT_MES_UTILIZACAO.ToString(CultureInfo.CreateSpecificCulture("pt-BR"))</td>
<td><span class="money" />#dados.VL_AMORTIZACAO</td>
<td><span class="money" />#dados.VL_RECEBIMENTO_MES</td>
<td><span class="money" />#dados.VL_ATRASO</td>
<td><span class="money" />#dados.VL_DAMP3</td>
</tr>
}
</table>
I need to check inside of the 'foreach' if i have some 'TB_OUTROS_DADOS' inside the 'od' list.
Thanks!
You can't do that in this way.
Pass List<> as model to you parent view or declare this list in same way like in partial view then do check, and if it is good pass it to partial view.
In this way:
#{
List<TB_OUTROS_DADOS> od = (List<TB_OUTROS_DADOS>)ViewData["outrosDados"];
<div class="table-responsive">
#{
if (od.Count > 0){
Html.Partial("~/Views/Outrosdados/Search.cshtml",od);
}
else
{
<table class="table table-striped">
<tr>
<th style="min-width:130px;">Mês</th>
<th style="min-width:80px;">Amortização</th>
<th style="min-width:100px;">Recebimento do Mês</th>
<th style="min-width:100px;">Atraso</th>
<th style="min-width:100px;">DAMP3</th>
</tr>
</table>
}
}
</div>
And in PartialView
#model List<TB_OUTROS_DADOS>
#using EixoX.Html;
#using Gestão.Models;
#using System.Globalization;
#{
Bootstrap3Presenter<TB_OUTROS_DADOS> presenter =
Bootstrap3Presenter<TB_OUTROS_DADOS>.GetInstance("pt-BR");
ViewBag.Title = "Outros Dados";
}
<table class="table table-striped">
<tr>
<th style="min-width:130px;">Mês</th>
<th style="min-width:80px;">Amortização</th>
<th style="min-width:100px;">Recebimento do Mês</th>
<th style="min-width:100px;">Atraso</th>
<th style="min-width:100px;">DAMP3</th>
</tr>
#foreach (TB_OUTROS_DADOS dados in Model){
<tr>
<td>#dados.DT_MES_UTILIZACAO.ToString(CultureInfo.CreateSpecificCulture("pt-BR"))</td>
<td><span class="money" />#dados.VL_AMORTIZACAO</td>
<td><span class="money" />#dados.VL_RECEBIMENTO_MES</td>
<td><span class="money" />#dados.VL_ATRASO</td>
<td><span class="money" />#dados.VL_DAMP3</td>
</tr>
}
</table>

if statement always print text

I need to print all the code under my question
if there is data in #store.GuaranteePolicy print all the <tr>. If there is no data, then print nothing.
No matter if there is data in or not in #store.GuaranteePolicy, then "Payment" is always printet, but why?
I said that if (store.GuaranteePolicy is different than null, then print)
The if statement is working with this:
If there is data in store.GuaranteePolicy everything is printed perfect
If there is no data in store.GuaranteePolicy the text is not printed, BUT the word Payment: is printed. So the whole <tr> is printed even if it is not true?
#if (store.GuaranteePolicy != null) {
<tr>
<th class="small-12 large-6 columns first">
<table>
<tr>
<th width="300">
<p class="text-left small-text-left"><strong>Payment:</strong></p>
</th>
</tr>
</table>
</th>
<th class="small-12 large-6 columns last">
<table>
<tr>
<th width="300">
<p class="text-left small-text-left">
<span>#store.GuaranteePolicy</span>
</p>
</th>
<th class="expander"></th>
</tr>
</table>
</th>
</tr>
}
If GuaranteePolicy is a collection try this:
#if(store.GuaranteePolicy != null && store.GuaranteePolicy.Count > 0)
{
}
if string:
#if(!string.IsNullOrWhiteSpace(store.GuaranteePolicy))
{
}
and so on...

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.

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