Since I'm using Web Application having NuGet Package's Microsoft.AspNet.Razor installed.
In WebForm pages (.aspx), I can use ResolveUrl() but in Razor pages (.cshtml), I get this error -->
"x:\Source\Foo.Dealer\Foo.Dealer.WebApp.Mobile\Member\DmsDashboard.cshtml(103): error CS0103: The name 'Url' does not exist in the current context"
Source-Code here..
#section HeadJavascriptLibraryFile
{
<script type="text/javascript" src="#Url.Content("~/scripts/webpages/setting-dmsdashboard.js")"></script>
}
and
<img src="#(Url.Content("~/images/miscellaneous/reportandpiechart2.png"))" alt="" />
Source Code as requested...
//LayoutMembmerGeneral.cshtml
#using Foo.Dealer.WebApp.Mobile.Infrastructure;
#{
if (LoginManagementTools.DealerUserLoginValidation_BrowsingPage(HttpContext.Current.Request, HttpContext.Current.Response, HttpContext.Current.Session) == false) { }
}<!DOCTYPE html>
<html>
<head>
<title>#Page.Title</title>
#RenderSection("HeadJavascriptLibraryFile", false)
</head>
<body>
#RenderBody()
</body>
</html>
//DmsDashboard.cshtml...
#using Foo.Dealer.WebApp.Mobile.Infrastructure
#using System.Web.Mvc;
#{
Page.Title = "A New Dawn In Auto Pricing";
Layout = "LayoutMemberGeneral.cshtml";
}
#section HeadJavascriptLibraryFile
{
}
<div id="WebLayout1">
<img src="#Url.Content("images/miscellaneous/reportandpiechart2.png")" alt="" />
</div>
The URL helper doesn't seem to exist in ASP.Net Web Pages (which is essentially what you are attempting to do), but you can simply use the following code to achieve the same effect:
<img src="~/images/miscellaneous/reportandpiechart2.png" alt="" />
The tilde (~) references the application root and is transformed when the page is compiled and sent to the client.
The tilde (~) is not transformed as part of any data- attributes and likely, other places also, though I haven't researched extensively.
If you happen to need this information in a place where the automatic transofmration isn't working, you can use the tilde equivalent, HttpContext.Current.Request.ApplicationPath.
In most Razor views, you should be able to shorten it to the following:
#Request.ApplicationPath
Reference: http://msdn.microsoft.com/en-us/library/system.web.httprequest.applicationpath.aspx
Another alternative in some situations is to use the VirtualPathUtility such as:
#VirtualPathUtility.ToAbsolute("~/")
Related
I have integrated SagePay's 'Drop In Checkout' into a test solution. The issue is, when I am submitting the form for the 'cardIdentifier', it is returned in the URL as a QueryString, rather than a hidden field, as per the documentation.
http://integrations.sagepay.co.uk/content/getting-started-integrate-using-drop-checkout
"Once the customer initiates the form submission, the payment details are validated, tokenised and passed as a hidden field called cardIdentifier which is then posted with the rest of the form contents"
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="CustomPayment.aspx.cs" Async="true" Inherits="SagePayDropInTest.CustomPayment" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://pi-test.sagepay.com/api/v1/js/sagepay-dropin.js"></script>
</head>
<body>
<div id="main">
<h1>My Test Shop</h1>
<form id ="checkout-form">
<h2>Payment Details</h2>
<div id="payment-details"></div>
<div id="submit-container">
<input type="submit"/>
</div>
</form>
</div>
<script>
sagepayCheckout({
merchantSessionKey: '<%=MerchID%>',
containerSelector: '#payment-details'
}).form({
formSelector: '#checkout-form'
});
</script>
</body>
</html>
C# CodeBehind
namespace SagePayDropInTest
{
public partial class CustomPayment : System.Web.UI.Page
{
public string MerchID = "";
protected void Page_Load(object sender, EventArgs e)
{
MerchID = GetMerchSessionID();
}}}
It does return the cardIdentifier, but just as a QueryString, but I would rather I was getting it as a hidden-field, as documented. The rest of the integration works as documented, it is just this step which is throwing me.
I am no doubt missing something obvious, and any guidance would be much appreciated.
Try changing the <form> tag to include a method="post" attribute. This should mean that the cardIdentifier is sent as a posted field rather than in the query string. The default method for a form is normally a GET request, the SagePay JS probably doesn't change this.
Also, there looks like an extra space in the <form id ="checkout-form"> tag as it is. I would recommend taking this out as some less forgiving browsers may not parse this correctly, breaking the CSS selector in your JS.
I've developed a simple web page with angularjs and spring framework.
I tried to make the web page using angular route so that web page work as SPA.
Here's my simple main jsp file. The page is shown when I access to 'http://localhost:8080/test' on the chrome.
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# page session="false" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-route.min.js"></script>
<script>
angular.module("app", ['ngRoute'])
.config(function($routeProvider) {
$routeProvider.when("/home", {
templateUrl: "home.html",
controller: "controller"
})
})
.controller("controller", function() {
});
</script>
</head>
<body ng-app="app" ng-controller="controller as main">
<ul>
<li>HOME</li>
</ul>
<ng-view></ng-view>
<div ng-view></div>
</body>
</html>
I want to put the home.html into <ng-view> or <div class="ng-view"> when I click the 'HOME' link without page refresh but it's not working.
What's the problem with the code?
To get it to work change href="#/home" to href="#!home"
Also, make sure home.html is in the /src/main/resources/static/ directory
I would prefer to use .html with Thymeleaf instead of .jsp
Read
Integrating JSP with AngularJS, Is it a concern in real world...Beginer in Angular JS
https://spring.io/blog/2015/08/19/migrating-a-spring-web-mvc-application-from-jsp-to-angularjs
I'm a newbie to angularJS and I'm trying to make the simple thing to work but I fail.
HTML:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<script src="main.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="main.css">
</head>
<body ng-app="app" ng-strict-di>
<div class="test" ng-controller="testSrc">
<p> {{ blah }} </p>
<img ng-src="{{ URLImage }}"/>
<button class="btn btn-sucess" ng-click="goYahoo()">Yahoo</button>
<button class="btn btn-sucess" ng-click="goGoogle()">Google</button>
</div>
</body>
</html>
JS:
var app = angular.module("app", []);
app.controller('testSrc', ['$scope,$location', function ($scope, $location) {
"use strict";
$scope.blah = "blah blah";
$scope.URLImage = 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/512px-Google_%22G%22_Logo.svg.png';
$scope.goGoogle = function () { $location.url('localhost:58164/g'); };
$scope.goYahoo = function () { $location.url('localhost:58164/y'); };
}]);
app.config(function ($routeProvider) {
"use strict";
$routeProvider
.when('/', {
templateUrl : 'index.html'
})
.when('/g', {
templateUrl : 'http://www.google.com'
})
.when('/y', {
templateUrl : 'http://www.yahoo.com'
});
});
The code has passed all lint warnings. I use the live preview of brackets that opens up Internet explorer. I encounter 3 issues:
1) {{ blah }} does not translate into blah blah, I see {{ blah }} as if the js is ignored. same for the ng-src of the img. It is ignored and I don't see the image.
2) the 2 buttons are not colored in green as I expect it to be from the bootstrap css. I tried it in jsFiddle and did see them as green but when I tried again now, they were regular, not sure what did I do wrong.
3) Routing: I want to browse to Google/Yahoo when navigating to specific url g and y using the 2 buttons. When I open the live preview, the url is: http://127.0.0.1:58164/index.html so how can I route this correctly? http://127.0.0.1:58164/index.html/g won't work.
I'm kinda lost here, not sure if the problem is my code, the browser of the live preview though the JS didn't work also in jsFiddle...
1) You're injecting the dependencies into your controller incorrectly - you need a string for each argument of the function. It's an easy mistake to make!
app.controller('testSrc', ['$scope,$location', function ($scope, $location) { // Wrong
app.controller('testSrc', ['$scope', '$location', function ($scope, $location) { // Right
2) You've misspelled the class name in your buttons. 'sucess' should be 'success'.
<button class="btn btn-sucess" ng-click="goYahoo()">Yahoo</button>
^^^^^^
3) There's numerous things wrong with your routing:
You haven't included the ngRoute module in your HTML - it hasn't been included in the base Angular package for a long time now.
Once that's done, you need to add it as a dependency: var app = angular.module("app", ["ngRoute"]); and add an ng-view tag to your HTML.
By default, the router will use 'hashbangs' for the URL - so the URL would be something along the lines of `http://127.0.0.1:58164/index.html#/g. If this isn't acceptable for you, I'd look into HTML5 mode.
All that being said, I don't think ngRoute will help you accomplish what you're trying to do. The router is designed to route through the pages of your app, not to external sites, so trying to load HTML from another domain probably won't work.
I'd recommend running through the official Angular tutorial if you haven't already - it covers all this stuff quite well. I'd also recommend Shaping Up With Angular.js on Code School, if you would prefer something a bit more hands-on.
I'm trying to follow along with this Sinatra tutorial (from 2008): http://devver.wordpress.com/2008/11/25/building-a-iphone-web-app-in-under-50-lines-with-sinatra-and-iui/
But ran into some problems with the code, for me the files aren't listed under the main heading currently. When I change dir to "./public/files/" the list is shown, but clicking a file's link results in an error page ("Sinatra doesn't know this ditty"). If I remove the public from the URL it will in this case work. How can I resolve the two?
Also, I get an error if with the line "use_in_file_template!", which I just comment out.
And I'm not familiar with CSS, so could someone tell me where I can the color of the text?
require 'rubygems'
require 'sinatra'
require 'pathname'
get "/" do
dir = "./files/"
#links = Dir[dir+"*"].map { |file|
file_link(file)
}.join
erb :index
end
helpers do
def file_link(file)
filename = Pathname.new(file).basename
"<li><a href='#{file}' target='_self'>#{filename}</a></li>"
end
end
use_in_file_templates!
__END__
## index
<html>
<head>
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<style type="text/css" media="screen">#import "/stylesheets/iui.css";</style>
<script type="application/x-javascript" src="/javascripts/iui.js"></script>
</head>
<body>
<div class="toolbar">
<h1 id="pageTitle"></h1>
</div>
<ul id="home" title="Your files, sir." selected="true">
<%= #links %>
</ul>
</body>
</html>
Well, sinatra (as many other web servers) assumes that public is a root directory for static files and it just does not use it when accessing files/dirs in it. So, in your case, you could change (add public to path when get list of files and remove it when generate links to them) some lines in your code:
get "/" do
dir = "public/files/"
#links = Dir[dir+"*"].map { |file|
file_link(file)
}.join
erb :index
end
helpers do
def file_link(file)
filename = Pathname.new(file).basename
"<li><a href='#{file.sub('public','')}' target='_self'>#{filename}</a></li>"
end
end
Trying to get Galleria script working in WordPress? I am have enqueued the script with this code, and it appears to be loading ok:
function add_scripts(){
// Load Galleria
wp_register_script('galleria',get_bloginfo('wpurl').'/galleria/galleria-1.2.2.min.js',array('jquery'),false);
wp_enqueue_script('galleria');
}
add_action('init','add_scripts');
In the post body I have the following, but all I get is the list of images:
<div id="gallery"><img src="http://farm4.static.flickr.com/3316/3532175582_91f984df47.jpg" alt="" />
<img src="http://farm4.static.flickr.com/3316/3532175582_91f984df47.jpg" alt="" />
<img src="http://farm4.static.flickr.com/3316/3532175582_91f984df47.jpg" alt="" /></div>
<script type="text/javascript">
Galleria.loadTheme('galleria/themes/classic/galleria.classic.min.js');
$("#gallery").galleria({
width: 500,
height: 500
});</script>
The error I receive is this: $ is not a function ... so the galleria script isn't firing right, or in the right order..
I have asked the question in the Galleria forum as well.
Thanks
This is the basic setup for Galleria, taken right from the documentation, which works fine as standalone html:
<!doctype html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="galleria/galleria-1.2.2.min.js"></script>
</head>
<body>
<div id="gallery">
<img src="photo1.jpg">
<img src="photo2.jpg">
<img src="photo3.jpg">
</div>
<script>
Galleria.loadTheme('galleria/themes/classic/galleria.classic.min.js');
$("#gallery").galleria({
width: 500,
height: 500
});
</script>
</body>
</html>
Try replacing $("#gallery") with jQuery("#gallery")
According to this post, Wordpress reserves $ for Prototype.
For some reason, sometimes with wordpress you gotta do like this:
var $ = jQuery;
Or do what #zxt suggested. That should work too. The version of jQuery they use doesn't declare $ variable to avoid conflicts if you are using other libraries that may use $.
You need to include the jquery library in your page -- jquery is what defines "$".
Something like
<script type="text/javascript" src="someplace/on/your/server/jquery.js"/>