I have the following variable that work very well on the code bellow, but I would like to add an if/else statement and I'm having some issue with the formatting. Any feedback would be greatly appreciated.
Before:
var originalSales = {
"RenewalDate": validateDefaultDateValue('#(Model.Program.RenewalDate.HasValue ?
Model.Program.RenewalDate.Value.AddYears(1).ToString("g") : "" )'),}
What I'm trying to Accomplish:
var originalSales = {
"RenewalDate": validateDefaultDateValue(#if((Model.Program.IsNonServiceYear) &&
(Model.ProgramCode.HasAutoRenewDate == true))
{('#(Model.Program.RenewalDate.HasValue ? Model.Program.RenewalDate.Value.AddYears(1).ToString("g") : "" )'),}
else
{('#(Model.Program.RenewalDate.HasValue ? Model.Program.RenewalDate.Value.ToString("g") : "" )'),}),
You can use this pattern:
#{
if ( Model.Program.IsNonServiceYear && Model.ProgramCode.HasAutoRenewDate )
{
originalSales =x;
}
else
{
originalSales =y;
}
}
Related
I have the following code :-
$hostheader = http.getHostHeader();
$path = http.getPath();
$languages = [‘cs’, ‘cs-cs’, ‘pt’, ‘pt-pt’, ‘fi’, ‘fi-fi’, ‘sl’, ‘sl-sl’, ‘el’, ‘el-gr’, ‘sr’, ‘sr-sr’, ‘ro’, ‘ro-ro’, ‘hu’, ‘hu-hu’, ‘es’, ‘sv’, ‘de’, ‘de-de’, ‘cn’, ‘zh’, ‘zh-cn’, ‘ru’, ‘ru-ru’, ‘fr’, ‘fr-fr’, ‘pl’, ‘pl-pl’, ‘at’, ‘ja’, ‘ja-jp’, ‘zh-hk’, ‘de-at’];
if ($hostheader == “website” ) {
foreach($lang in $languages) {
if (string.endsWithI($path, $lang) ) {
http.setResponseHeader(“Host”, “host”);
http.setHeader(“Host”, “host” . $lang);
if(!ssl.isSSL()) {
pool.use(“cms-splash-https-Pool”);
}
else {
pool.use(“cms-splash-http-Pool”);
}
}
}
}
if( http.getHostHeader() == "host" ) {
http.changeSite( "newwebsite" );
}
I want to redirect without change the URL so no one will notice anything , is this possible ?
I am trying to attach class dynamically in table's tr in Angular js like bellow :
ng-class="{
'text-light' : inventory.newValue.disabled,
'odd' : inventory.rowNumber % 2 === 1,
{{inventory.first? 'loc-'unit.attachNumber : 'bldg-'inventory.parent.attachNumber }}
}"
But it's not working,can anyone help me out how can I do this in AngularJs. Also I can't put this in controller.
You forgot the string concatenation operator +:
'loc-'+unit.attachNumber
'bldg-'+inventory.parent.attachNumber
Furthermore the last member of you object is not valid. It is missing a key, we can only see a value.
You can try this:
ng-class="{
'text-light' : inventory.newValue.disabled,
'odd' : inventory.rowNumber % 2 === 1,
'attachNumber' : inventory.first? 'loc-'+unit.attachNumber : 'bldg-'+inventory.parent.attachNumber }}
}"
if you use a lot of condition it is better write a function. in this way you will have a clear code and debuggable code.
like this in your controller
$scope.getRightClass = function(inventory, unit){
var classes = [];
if(inventory.newValue.disabled === true){
classes.push('text-light');
}
if(inventory.rowNumber % 2 === 1){
classes.push('odd');
}
if(inventory.first === true){
classes.push('loc-' + unit.attachNumber)
}else{
classes.push('bldg-' + inventory.parent.attachNumber);
}
return classes.join(' ');
}
and this in your view
ng-class="getRightClass(inventory, unit)"
I am very new to web development and I've been searching around for a while now and I can't seem to find a solution to this. I am using razor pages in asp.net core 2.0 and I want to fill a drop down box based on another drop down box's selection. I set up the below javascript to hit a procedure in my razor page when the value of the first drop down box changes. When I run the code though, I can't get it to work. I think it is due to my return value but I can't seem to get that to be a json value as it keeps throwing an error at me when I try to. The error is that "JSON is not valid in this context". Can anyone suggest to me how to return JSON from razor pages to a javascript call?
Any help would be appreciated!
#section Scripts {
<script type="text/javascript">
$('#Department').change(function () {
var selectedDepartment = $("#Department").val();
var cardSelect = $('#Card');
cardSelect.empty();
if (selectedDepartment != null && selectedDepartment != '') {
$.getJSON('#Url.Action("GetCardsByDivisionAndStatus")', { divisionID: selectedDepartment }, function (cards) {
if (cards != null && !jQuery.isEmptyObject(cards)) {
cardSelect.append($('<option/>', {
Card_ID: null,
Card_Number: ""
}))
$.each(cards, function (index, card) {
cardSelect.append($('<option/>', {
Card_ID: card.Card_ID,
Card_Number: card.Card_Number
}));
});
};
});
}
});
</script>
}
And here is my C# code (I tried used JsonResult but that's not working either):
// If the user selects a division then make sure to get the cards for that division only
[HttpGet]
public ActionResult GetCardsByDivisionAndStatus(string divisionID)
{
int checkinStatus;
int intdivisionID;
if (divisionID != "0" && divisionID != null)
{
// Retrieve a status of checked in so that only cards with a checked in status can
// be checked out.
checkinStatus = linqQuery.GetCardStatusByStatusDesc("Checked In", _Context);
intdivisionID = Convert.ToInt32(divisionID);
// Retrieve list of cards that have the checkin status ID
CardList = linqQuery.GetCardListByStatusIDandDeptID(checkinStatus, intdivisionID, _Context);
// Create the drop down list to be used on the screen.
carddropdown = new List<CardDropDown>();
carddropdown = loaddropdowns.ReturnDropDownList(CardList);
return new JsonResult(CardList);
}
return null;
}
EDIT----------------------------------------------------------------------
So I changed the code as below and now I'm getting a parse error "JSON.parse: unexpected character at line 1 column 1 of the JSON data" I can't figure out what is going on as I can't see what the data is coming back that it can't parse. Is my code below not converting to JSON and if not, what am I missing?
#section Scripts {
<script type="text/javascript">
$('#Department').change(function () {
var selectedDepartment = $("#Department").val();
var cardSelect = $('#Card');
cardSelect.empty();
if (selectedDepartment != null && selectedDepartment != '') {
$.getJSON('#Url.Action("/CheckOutCard?handler=CardsByDivisionAndStatus")', { divisionID: selectedDepartment }, function (cards) {
if (cards != null && !jQuery.isEmptyObject(cards)) {
cardSelect.append($('<option/>', {
Card_ID: null,
Card_Number: ""
}))
$.each(cards, function (index, card) {
cardSelect.append($('<option/>', {
Card_ID: card.Card_ID,
Card_Number: card.Card_Number
}));
});
};
});
}
});
</script>
And here is my C# code for the procedure that I updated:
// If the user selects a division then make sure to get the cards for that division only
[HttpGet]
public JsonResult OnGetCardsByDivisionAndStatus(string divisionID)
{
int checkinStatus;
int intdivisionID;
if (divisionID != "0" && divisionID != null)
{
// Retrieve a status of checked in so that only cards with a checked in status can
// be checked out.
checkinStatus = linqQuery.GetCardStatusByStatusDesc("Checked In", _Context);
intdivisionID = Convert.ToInt32(divisionID);
// Retrieve list of cards that have the checkin status ID
CardList = linqQuery.GetCardListByStatusIDandDeptID(checkinStatus, intdivisionID, _Context);
// Create the drop down list to be used on the screen.
carddropdown = new List<CardDropDown>();
carddropdown = loaddropdowns.ReturnDropDownList(CardList);
var converted = JsonConvert.SerializeObject(carddropdown);
return new JsonResult(converted);
}
return null;
}
Rename your method to OnGetCardsByDivisionAndStatus (note "OnGet" prefix) and in jquery code change the url to
$.getJSON('/{PageRoute}?handler=CardsByDivisionAndStatus'
e.g.
$.getJSON('/About?handler=CardsByDivisionAndStatus'
Notice the handler querystring parameter name will be your method name without OnGet prefix.
So I figured out what the problem was. Apparently I did not need to have the #URL.Action in my code. It was causing me to not hit my C# code which in return caused a null response back to my call. I have modified my javascript code to be as below to show what I am talking about. Thanks Mohsin for trying to help me out.
#section Scripts {
<script type="text/javascript">
$('#Department').change(function ()
{
var selectedDepartment = $("#Department").val();
var cardSelect = $('#Card');
cardSelect.empty();
if (selectedDepartment != null && selectedDepartment != '')
{
$.getJSON("/CheckOutCard?handler=CardsByDivisionAndStatus", { divisionID: selectedDepartment }, function (cards)
{
$.each(cards, function (index, card)
{
cardSelect.append($('<option/>',
{
value: card.card_ID,
text: card.card_Number
}));
});
});
}
});
</script> }
How to Write Condition on data which is fetching from Json to Angularjs?
Example : if user FIRM NAME exists Show else if user FULL NAME exists Show else Show REALNAME
I have a working Example of fetching data
at line number 25 <h3 class="moduletitle">Name : {{ module.realname }}</h3>
Please See that in PLUNKER
I hope i will get the working code update along with PLUNKER
I can suggest you have a function that returns the entity in which you want to display. Then using ng-show / ng-hide to display/hide the things you want.
Example:
function pseudoDecide(){
var displaythis = "";
if(/*boolean exp*/){ displaythis = "firm" }
else if(/*boolean exp*/) { displaythis = "full" }
else(/*boolean exp*/) { displaythis = "real" }
return displaythis;
}
Then <div ng-show="{{psedoDecide() === 'firm'}}>" etc etc, something like that.
With AngularJS 1.1.5+, you can use the ternary operator inside an expression. In your case, I believe you want something like:
<h3 class="moduletitle">Name : {{ module.firmname ? module.firmname : (module.fullname ? module.fullname : module.realname)) }}</h3>
If you don't want a nested ternary in your template, you could also go this route:
Somewhere in your controller:
$scope.pickName = function (module) {
var val;
if (module.firm_name) {
val = module.firm_name;
} else if (module.full_name) {
val = module.full_name;
} else {
val = module.realname;
}
return val;
};
And in your template:
<h3 class="moduletitle">Name : <span ng-bind="pickName(module)"></span></h3>
I recently needed to move to using a JST file for all my templates so I don't have a clutter of html templates everywhere.
I am building the JST file with grunt (using grunt-contrib-jst) and it creates the file "build/templates.js".
Below is an entry from there:
this["JST"] = this["JST"] || {};
this["JST"]["build/html/template-1.html"] = function(obj) {obj || (obj = {});var __t, __p = '', __e = _.escape;with (obj) {__p += ' <script type="text/template" id="template-1">\n <span id="chat_title_1">' +((__t = ( title )) == null ? '' : __t) +'</span>\n <span id="chat_symbol_1">▲</span>\n </script>';}return __p};
I updated my backbone.marionette render method as per https://github.com/marionettejs/backbone.marionette/wiki/Using-jst-templates-with-marionette, where it asks to replace the Renderer.render method. See the change below:
Marionette.Renderer = {
render: function(template, data){
if (!JST[template]) throw "Template '" + template + "' not found!";
return JST[template](data);
}
};
So I have the following in my view:
App.ChatBoxView = Backbone.Marionette.Layout.extend({
template: "build/html/template-1.html",
...
The page loads, there are no errors or anything, but there is nothing rendering on the page, no views, etc.
Is there something missing or done wrong?
Thank you.
Solved it... my template html files still had the <script ....> at the start and end. Removing that worked.
Updated entry example in "templates.js":
this["JST"] = this["JST"] || {};
this["JST"]["build/html/template-1.html"] = function(obj) {obj || (obj = {});var __t, __p = '', __e = _.escape;with (obj) {__p += '<span id="chat_title_1">' +((__t = ( title )) == null ? '' : __t) +'</span>\n <span id="chat_symbol_1">▲</span>';}return __p};