MVC3 ASP Replace null value with empty space on the view - asp.net-mvc-3

I have the following view which returns some text if the POnumber is null.
What I think I need to have instead of the if(Model.Invoice.PONumber == null) is a check mechanism ( maybe multiple if statements ) that will check the fields LineNumber, Description, UnitOfMeasure, QtyOrdered and if any of them is null it will replace it with N/A or empty space but it will still allow the user to see the rest of information available.
Do you have any sugestions? I am new to MVC and any help will be apreciated.
Thank you in advance for your time and help,Bobby
<div class="contentWrapper2">
<div class="content2">
<div class="clr lfl w100">
<h1>Invoice Detail</h1>
<div class="return-btn">
<a class="btn btnStyleC btn-back-invoice" href="#Url.Action("InvoiceHistory", "Account")">
Back to Invoice List</a>
</div>
</div>
#if (Model.ErpError.Length > 0)
{
<div class="clr lfl w100 error">
#Html.Raw(Model.ErpError)
</div>
}
else
{
if(Model.Invoice.PONumber == null)
{
<div class="lfl w100 clr messaging">
<p>No information available at the moment for current invoice.
Please call our sales department for further assistance.
</p>
</div>
}
else
{
<div class="clr lfl w100">
<div class="order-number-date">
<table>
<tr>
<th class="col-1">
<h3>Invoice #:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.InvoiceNumber</h3>
</td>
</tr>
<tr>
<th class="col-1">
<h3>Invoice Date:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.InvoiceDate.ToShortDateString()</h3>
</td>
</tr>
</table>
</div>
<div class="order-number-date">
<table>
<tr>
<th class="col-1">
<h3>Order #:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.OrderNumber</h3>
</td>
</tr>
<tr>
<th class="col-1">
<h3>PO #:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.PONumber</h3>
</td>
</tr>
<tr>
<th class="col-1">
<h3>Due Date:</h3>
</th>
<td class="col-2">
<h3>#Model.Invoice.DueDate.ToShortDateString()</h3>
</td>
</tr>
</table>
</div>
</div>
<div class="clr lfl w100">
<div class="bill-ship">
<table>
<tr>
<th>
<h4>Billing Information</h4>
</th>
</tr>
<tr>
<td>#Model.Invoice.BTDisplayName
</td>
</tr>
<tr>
<td>
<#Html.Raw(Model.Invoice.BTAddress1)
</td>
</tr>
#if (!string.IsNullOrEmpty(Model.Invoice.BTAddress2))
{
<tr>
<td>#Html.Raw(Model.Invoice.BTAddress2)
</td>
</tr>
}
<tr>
<td>#Html.CityCommaStateZip(Model.Invoice.BTCity, Model.Invoice.BTState, Model.Invoice.BTZip)</td>
</tr>
<tr>
<td>#Model.Invoice.BTCountry
</td>
</tr>
<tr>
<td>#Model.Invoice.BTPhone1</td>
</tr>
<tr>
<td>#Model.Invoice.BTEmail
</td>
</tr>
</table>
</div>
</div>
if (Model.Invoice.InvoiceLines.Count > 0)
{
<div class="clr lfl w100 line-item-detail">
<table class="info-tbl">
<tr>
<th class="vid-item">Item #</th>
<th class="vid-desc">Description</th>
<th class="vid-um">
U/M
</th>
<th class="vid-qty">
Qty
</th>
<th class="vid-ship">
Ship Date
</th>
#if (Model.ShowPackslip)
{
<th class="vid-pack">Pack Slip</th>
}
<th class="vid-unit">Unit Price</th>
<th class="vid-ext">Ext Price</th>
</tr>
#foreach (var invoiceLine in Model.Invoice.InvoiceLines)
{
<tr>
<td class="vid-line">#invoiceLine.LineNumber</td>
<td class="vid-desc">#invoiceLine.Description</td>
<td class="vid-um">#invoiceLine.UnitOfMeasure</td>
<td class="vid-qty">#invoiceLine.QtyOrdered</td>
<td class="vid-ship">
#if (invoiceLine.ShipDate.ToShortDateString() == "1/1/0001")
{
}
else
{
#invoiceLine.ShipDate.ToShortDateString()
}
</td>
#if (Model.ShowPackslip)
{
<td class="vid-pack">
#invoiceLine.PackSlip
</td>
}
<td class="vid-unit">#invoiceLine.UnitPrice.ToCurrency()
</td>
<td class="vid-ext">#invoiceLine.ExtendedPrice.ToCurrency()
</td>
</tr>
}
</table>
</div>
}
<div class="clr lfl w100">
<table class="tbl-total">
<tr class="subtotal">
<th class="col-1">Subtotal</th>
<td class="col-2">#Model.Invoice.OrderSubTotal.ToCurrency()
</td>
</tr>
#if (Model.Invoice.DollarOffOrder > 0)
{
<tr>
<th class="col-1">Order Discount</th>
<td class="col-2">#Model.Invoice.DollarOffOrder.ToCurrency()</td>
</tr>
}
#if (Model.Invoice.ShippingAndHandling > 0)
{
<tr>
<th class="col-1">Shipping</th>
<td class="col-2">#Model.Invoice.ShippingAndHandling.ToCurrency()
</td>
</tr>
}
#if (Model.Invoice.MiscCharges > 0)
{
<tr>
<th class="col-1">Misc. Charges</th>
<td class="col-2">#Model.Invoice.MiscCharges.ToCurrency()</td>
</tr>
}
<tr>
<th class="col-1">Sales Tax</th>
<td class="col-2">#Model.Invoice.TotalTax.ToCurrency()</td>
</tr>
<tr>
<th class="col-1">Invoice Total</th>
<td class="col-2">#Model.Invoice.InvoiceTotal.ToCurrency()</td>
</tr>
</table>
</div>
<div class="clr lfl w100">
<a class="btn btnStyleB btn-print" href="javascript:window.print();">Print</a>
</div>
}
}
</div>
</div>

You could create a template called for example "nullcheck.cshtml" like:
#if (ViewBag.ValueToCheck == null) {
<div class="lfl w100 clr messaging">
<p>
No information available at the moment for #(ViewBag.Field).
Please call our sales department for further assistance.
</p>
</div>
}
else {
#Html.Partial(ViewBag.TargetTemplate, Model)
}
Then you call it from your main view:
#{
ViewBag.TargetTemplate = "okModel";
ViewBag.Field = "P.O.Number";
ViewBag.ValueToCheck = Model.Invoice.PONumber;
Html.RenderPartial("nullCheck", Model, ViewBag);
}
okModel.cshtml should be the part of your template you will display when the value is not null...
I haven't tested this myself but it should give you some ideas... contact me if things go wrong XD
Cheers!

This seems like something you should take care of in your controller.
public ActionResult YourControllerAction()
{
var myViewModel = SomeService.GetMyViewModel();
if (myViewModel.Invoice.PONumber == null)
{
myViewModel.Invoice.PONumber = "N/A";
}
//etc
}
This leaves your view clearer (my personal preference)
However in the view you could simply use the null coalescing operator like so:
#Model.Invoice.PONumber ?? "NA"

Related

Laravel Livewire checkbox checked on edit page

I'm facing an issue with checking the checkbox on the edit page using Livewire. I've tried many ways but still not able to check the old selected value
View Code:
<table id="branches" class="table table-bordered table-sm" width="100%" cellspacing="0">
<thead>
<tr>
<th width="10%">
</th>
<th>Branch ID</th>
</tr>
</thead>
<tbody>
#foreach ($propertiesOptions as $key => $property)
<tr>
<td>
<input class="branchCheckbox"
type="checkbox"
wire:model="propertyIds.{{$property->id}}"
value="{{$property->id}}" #if(in_array($property->id,$propertyIds)) checked #endif>
</td>
<td>{{$property->id}}</td>
</tr>
#endforeach
</tbody>
</table>
Backend Code:
public $propertyIds, $propertiesOptions;
public function mount($record)
{
$this->propertiesOptions = Properties::where('merchant_id',$record->id)->get()
$this->propertyIds = $record->properties->pluck('property_id')->toArray();
}```
updated
And can you check if this correct? wire:model="propertyIds.{{$property->id}}"? Try to delete the wire:model .
<input class="branchCheckbox" type="checkbox"
value="{{$property->id}}"
#if(in_array($property->id,$propertyIds)) checked #endif>
`<table id="branches" class="table table-bordered table-sm" width="100%" cellspacing="0">
<thead>
<tr>
<th width="10%">
</th>
<th>Branch ID</th>
</tr>
</thead>
<tbody>
#foreach ($propertiesOptions as $key => $property)
<tr>
<td>
<input class="branchCheckbox"
type="checkbox"
wire:model="propertyIds"
value="{{$property->id}}" >
</td>
<td>{{$property->id}}</td>
</tr>
#endforeach
</tbody>
</table>`
BACKEND
public $propertyIds, $propertiesOptions;
public function mount($record)
{
$this->propertiesOptions = Properties::where('merchant_id',$record->id)->get()
$this->propertyIds = $record->properties->pluck('property_id')->toArray();
}

How can I fix Laravel table going off page

I have a table which I have created in a laravel blade, I've used bootstrap for this but my table seems to span off the screen, I have never really used laravel and normally my tables have auto centred as needed, I'm hoping someone can make some suggestions or share snippets to help me out :)
I have this image here:
I thought I should also put my blade in but only put the form-group as it will save your guys time :)
<div class="form-group">
<table id="userTable" data-page-length='5' cellspacing="0"
class="table table-bordered table-striped table-hover table-condensed"
role="grid">
<thead>
<tr>
<th scope="col">MESSAGE ID</th>
<th scope="col">MSISDN</th>
<th scope="col">MO/MT</th>
<th scope="col">TYPE</th>
<th scope="col">SENT/RECEIVED</th>
<th scope="col">TITLE</th>
<th scope="col">ORIENTATION</th>
<th scope="col">DESCRIPTION</th>
<th scope="col">IMAGE URL</th>
<th scope="col">ALIGNMENT</th>
<th scope="col">STATUS</th>
</tr>
</thead>
<tbody>
<tr>
<td style='font-size:14px'>{{$message->id}}</td>
<td>{{$message->msisdn}}</td>
<td class="text-center">
#if ($message->direction == 'mo')
<span class='badge badge-warning'>mo</span>
#else
<span class='badge badge-success'>{{$message->direction}}</span>
#endif
</td>
<td>{{$message->type}}</td>
<td>{{$message->created_at}} </td>
<td>{{$message->content->richCard->standaloneCard->cardOrientation}}</td>
<td>{{$message->content->richCard->standaloneCard->cardContent->title}}</td>
<td>{{$message->content->richCard->standaloneCard->cardContent->description}}</td>
<td>{{$message->content->richCard->standaloneCard->cardContent->media->contentInfo->fileUrl}}</td>
<td>{{$message->content->richCard->standaloneCard->thumbnailImageAlignment}}</td>
<td class="text-center">
#if ($message->status == 'NOK')
<span class='badge badge-danger'>NOK</span>
#elseif ($message->status == 'received')
<span class='badge badge-info'>received</span>
#elseif ($message->status == 'delivered')
<span class='badge badge-primary'>delivered</span>
#elseif ($message->status == 'queued')
<span class='badge badge-warning'>queued</span>
#elseif ($message->status == 'read')
<span class='badge badge-success'>read</span>
#elseif ($message->status == 'sent')
<span class='badge badge-success'>sent</span>
#endif
</td>
</tr>
</tbody>
</table>
</div>
Any help would be greatly appreciated as I've never had this before.
before your table tag use
<div class='table-responsive'>
and close the div after closing your table tag.
This worked for me in some cases.
You will have to use table-responsive
<div class="table-responsive">
<table class="table">
...
</table>
</div>

Unable to select column with its header through XPath

My HTML
<table id="flex1" cellspacing="0" cellpadding="0" border="0">
<thead>
<tr class="hDiv">
<th width="6%">
<div class="text-left field-sorting asc" rel="IFSC_CODE"> IFSC CODE </div>
</th>
<th width="6%">
<div class="text-left field-sorting " rel="BRANCH_NAME"> BRANCH NAME </div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="sorted" width="6%">
<div class="text-left">SACS011151</div>
</td>
<td width="6%">
<div class="text-left">check</div>
</td>
</tr>
<tr class="erow">
<td class="sorted" width="6%">
<div class="text-left">SACS011152</div>
</td>
<td width="6%">
<div class="text-left">Motiram</div>
</td>
</tr>
<tr class="erow">
<td class="sorted" width="6%">
<div class="text-left">SACS011158</div>
</td>
<td width="6%">
<div class="text-left">TESTNAME</div>
</td>
</tr>
</tbody>
</table>
My XPath
//table/tbody/tr/td[count(//table/thead/tr/th[.='BRANCH NAME']/preceding-sibling::th)+4]
Above XPath is Selecting all the column but not selecting its header name 'BRANCH NAME' and I want to select the header name with all its column.Any Idea how to do this?
You can simply use xpath union operator (|) to combine two xpath queries, for example* :
//table/tbody/tr/td[count(//table/thead/tr/th[.='BRANCH NAME']/preceding-sibling::th)+4]
|
//table/thead/tr/th[.='BRANCH NAME']
*: formatted into multiple lines just to make it visible without horizontal scroll

Escaping characters with ajax and ColdFusion

Hello I've got an issue with an encode failing. Can anyone spot where I'm going wrong?
<form>
<table cellspacing="0" cellpadding="0" border="0" style="background-color:#ededed;padding:50px;">
<tr>
<td align="left"><b>Screen? (eg. Index)</b></td>
</tr>
<tr>
<td align="left"><input type="text" name="strFeedbackScreen" value="" style="width:300px;"></td>
</tr>
<tr>
<td style="height:10px"></td>
</tr>
<tr>
<td align="left"><b>Comments:</b></td>
</tr>
<tr>
<td align="left"><textarea name="strFeedbackComments" style="width:400px;height:150px;"></textarea></td>
</tr>
<tr>
<td style="height:10px"></td>
</tr>
<tr>
<td align="left"><b>Thank you for your feedback.</b></td>
</tr>
<tr>
<td style="height:10px"></td>
</tr>
<cfoutput>
<tr>
<td align="left"><input type="button" value="Send" class="button"
onMouseover="this.className = 'buttonover';"
onMousedown="this.className = 'buttonover';"
onMouseOut="this.className = 'button';"
onclick="sendfeedback('strFeedbackScreen='+escape(this.form.strFeedbackScreen.value)+',strFeedbackComments='+escape(this.form.strFeedbackComments.value),'send_feedback_action_ajax')">
</td>
</tr>
</cfoutput>
</table>
</form>
is the form
<cfoutput>
<cfmail to="feedback#example.com" from="feedback#example.com" subject="Feedback left" type="html">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>**** This email has been sent to all concerned ****</td>
</tr>
<tr>
<td style="height:10px;"> </td>
</tr>
<cfif application.ds eq "App1">
<tr>
<td>This feedback has been left on App 1.</td>
</tr>
<cfelseif application.ds eq "App2">
<tr>
<td>This feedback has been left on App 2.</td>
</tr>
<cfelseif application.ds eq "App3">
<tr>
<td>This feedback has been left on App 3.</td>
</tr>
</cfif>
<tr>
<td style="height:10px;"> </td>
</tr>
<tr>
<td><b>From:</b></td>
</tr>
<tr>
<td>#session.stafffirstname# #session.staffsurname# - #session.staffemail#</td>
</tr>
<tr>
<td style="height:10px;"> </td>
</tr>
<tr>
<td><b>Screen:</b></td>
</tr>
<tr>
<td>#strFeedbackScreen#</td>
</tr>
<tr>
<td style="height:10px;"> </td>
</tr>
<tr>
<td><b>Comments:</b></td>
</tr>
<tr>
<td>#strFeedbackComments#</td>
</tr>
</table>
</cfmail>
</cfoutput>
is the action.cfm
and the javascript is
function sendfeedback(fields,action) {
turnLayeron('ajaxloading');
nocache = Math.random();
http.open('get', '/ajax.cfm?action='+action+'&fields='+fields+'&nocache='+nocache);
http.onreadystatechange = function() {
if(http.readyState == 4){
closepopout();
turnLayeroff('ajaxloading');
}
};
http.send(null);
}
I've been trying to get uriencode working, but it encodes my string before it gets emailed.
Change your JavaScript to following:
function sendfeedback(fields,action) {
http.open("POST", '/ajax.cfm?action='+action+'&nocache='+nocache, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
if(http.readyState == 4){
closepopout();
turnLayeroff('ajaxloading');
}
};
http.send(fields);
}
Also change your function call to:
onclick="sendfeedback('strFeedbackScreen='+escape(this.form.strFeedbackScreen.value)+'&strFeedbackComments='+escape(this.form.strFeedbackComments.value),'send_feedback_action_ajax')"

Grid generated with JQuery template need to reset using Ajax not working

Sometime working and sometime not.
I am trying to generate Grid with the help of JQuery Template via Ajax once record is added or deleted. In js file
$('.gridRow').remove();
is not working properly. Someone tell me how to reset grid to fill it again. Below is the code.
JS File
var ReloadGrid = (function(){
$.getJSON("/HeaderMenu/GetHeaderGrid", function(data) {
$('.gridRow').remove();
(data.length <= 0) ? $("#gridBtn").hide() : $("#gridBtn").show();
for (var i=0; i<data.length; i++) { data[i].num = i+1; }
$('#gridTemplate').tmpl(data).appendTo('table.gridTable > tbody');
});
});
on MVC3 cxhtml page
<script id="gridTemplate" type="text/x-jquery-tmpl">
<tr class="gridRow">
<td class="cellTd ">
<input type="checkbox" id="deleteCb" />
<input type="hidden" id="Id_ + ${num}" class="idField" value="${Id}" />
</td>
<td class="cellTd">
<input id="index" name="index" class="numberField" type="text" value="${IndexOrder}" />
</td>
<td class="cellTd">${DisplayName}</td>
<td class="cellTd ">${UrlName}</td>
<td class="cellTd ">
<input type="checkbox" id="activeCb" {{if Active}} checked{{/if}} />
</td>
</tr>
</script>
<div class="gridDiv">
<table class="gridTable" cellspacing="0" cellpadding="0">
<tbody>
<tr class="gridTitleRow">
<td class="iconLink width36">Delete</td>
<td class="iconLink width60">Sort Order</td>
<td class="iconLink widthAuto">Display Name</td>
<td class="iconLink widthAuto">Url Name</td>
<td class="iconLink widthAuto">Active</td>
</tr>
</tbody>
</table>
</div>
I usually empty the wrapper instead of the row.
$('table.gridTable > tbody').empty();
But for that to work you'd have to change your table to use thead
<table class="gridTable" cellspacing="0" cellpadding="0">
<thead>
<tr class="gridTitleRow">
<th class="iconLink width36">Delete</th>
<th class="iconLink width60">Sort Order</th>
<th class="iconLink widthAuto">Display Name</th>
<th class="iconLink widthAuto">Url Name</th>
<th class="iconLink widthAuto">Active</th>
</tr>
<thead>
<tbody>
</tbody>
</table>

Resources