fullcalendar in VB.Net ASP MVC - asp.net-mvc

I try to make a scheduler using fullcalendar. I cannot find a tutorial that use vb.net. So i follow this tutorial A complete web diary system for jQuery and C# MVC by converting c# code into vb.net. But i have problem to display the calendar. I have added fullcalendar.js to my scripts folder and fullcalendar.css into content folder. But the result shows nothing. A blank page. This is my html code:
<div class="row">
<div id='calendar' style="width:65%"></div>
<script>
$(document).ready(function () {
$('#calendar').fullcalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultView: 'agendaDay',
editable: true,
allDaySlot: false,
selectable: true,
slotMinutes: 15,
});
})
</script>

You need to include the CSS and JS on the page. Just adding them to the folders is probably not enough.
Include them in _Layout.cshtml (which makes them available on all pages)
Include them in the current view (this page only)
Example:
<link href="#Url.Content("~/Content/fullcalendar.css")" rel="stylesheet" type="text/css" />
<script src="#Url.Content("~/Scripts/fullcalendar.js")" type="text/javascript"></script>
Also you have an unclosed <div class="row">

Related

Mvc: $(...).DataTable is not a function [duplicate]

I am trying to work with jQuery's Datatable JS for my project from this link.
I downloaded the complete library from the same source. All the examples given in the package seem to work fine, but when I try to incorporate them in my WebForms,the CSS,JS do not work at all.
Here is what I have done :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="myTable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
<tbody>
<!-- table body -->
</tbody>
</table>
</div>
<script src="js/jquery.dataTables.js" type="text/javascript"></script>
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#myTable').DataTable();
});
</script>
</form>
</body>
</html>
My file structure for the JS and CSS in my Solution looks as follows :
I have added all the necessary JS and CSS references as shown in the manual. Still the rendering isn't as expected. There is no CSS and even the JS doesn't work.
Also in the console i get the following errors:
ReferenceError: jQuery is not defined
TypeError: $(...).DataTable is not a function
I have still not bound any dynamic data here (like within a repeater or so) still it is not working.
Can someone please guide me in the right direction for this problem ?
CAUSE
There could be multiple reasons for this error.
jQuery DataTables library is missing.
jQuery library is loaded after jQuery DataTables.
Multiple versions of jQuery library is loaded.
SOLUTION
Include only one version of jQuery library version 1.7 or newer before jQuery DataTables.
For example:
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/jquery.dataTables.min.js" type="text/javascript"></script>
See jQuery DataTables: Common JavaScript console errors for more information on this and other common console errors.
This worked for me. But make sure to load the jquery.js before the preferred dataTable.js file. Cheers!
<script type="text/javascript" src="~/Scripts/jquery.js"></script>
<script type="text/javascript" src="~/Scripts/data-table/jquery.dataTables.js"></script>
<script>$(document).ready(function () {
$.noConflict();
var table = $('# your selector').DataTable();
});</script>
I got this error because I found out that I referenced jQuery twice.
The first time: on the master page (_Layout.cshtml) in ASP.NET MVC, and then again on one current page so I commented out the one on the master page.
If you are using ASP.NET MVC this snippet could help you
#*#Scripts.Render("~/bundles/jquery")*#//comment this line
#Scripts.Render("~/bundles/bootstrap")
#RenderSection("scripts", required: false)
and in the current page I added these lines
<script src="~/scripts/jquery-1.10.2.js"></script>
<!-- #region datatables files -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" />
<script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<!-- #endregion -->
Hope this help you even if don't use ASP.NET MVC
if some reason two versions of jQuery are loaded (which is not recommended), calling $.noConflict(true) from the second version will return the globally scoped jQuery variables to those of the first version.
Sometimes it could be issue with older version (or not stable) of JQuery files
Solution use $.noConflict();
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.dataTables.js" type="text/javascript"></script>
<script>
$.noConflict();
jQuery( document ).ready(function( $ ) {
$('#myTable').DataTable();
});
// Code that uses other library's $ can follow here.
</script>
Here is the complete set of JS and CSS required for the export table plugin to work perfectly.
Hope it will save your time
<!--Import jQuery before export.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<!--Data Table-->
<script type="text/javascript" src=" https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src=" https://cdn.datatables.net/buttons/1.2.4/js/dataTables.buttons.min.js"></script>
<!--Export table buttons-->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.24/build/pdfmake.min.js" ></script>
<script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.24/build/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.4/js/buttons.html5.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.1/js/buttons.print.min.js"></script>
<!--Export table button CSS-->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.2.4/css/buttons.dataTables.min.css">
javascript to add export buttons on the table with id = tbl
$('#tbl').DataTable({
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
]
});
Result :-
Same error occurs when working with DataTables in a Laravel project. Even if the following solutions are tried, the error still remains:
making sure jQuery is included
include jQuery before including the DataTables
making sure only one version of jQuery is added
In order to remove the error, after making sure the above conditions are fulfilled, add "defer" to the tag which includes the DataTables. For example,
<script src="https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js" defer></script>
There can be two reasons for that error:
First
You are loding jQuery.DataTables.js before jquery.js so for that :-
You need to load jQuery.js before you load jQuery.DataTables.js
Second
You are using two versions of jQuery.js on the same page so for that :-
Try to use the higher version and make sure both links have same version of jQuery
I tried many things but my solution was adding "defer" after html script that you included datatables.
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.js" defer></script>
Honestly, this took hours to get this fixed. Finally only one thing worked a reconfirmation to solution provided by "Basheer AL-MOMANI". Which is just putting statement
#RenderSection("scripts", required: false)
within _Layout.cshtml file after all <script></script> elements and also commenting the jquery script in the same file. Secondly, I had to add
$.noConflict();
within jquery function call at another *.cshtml file as:
$(document).readyfunction () {
$.noConflict();
$("#example1").DataTable();
$('#example2').DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"info": true,
"autoWidth": false,
});
});
I know its late
Buy can help someone
This could also happen if you don't add $('#myTable').DataTable(); inside the document.ready
So instead of this
$('#myTable').DataTable();
Try This
$(document).ready(function() {
$('#myTable').DataTable();
});
I have Added defer to the data table jquery library reference. Now it is working for me.
<script src="~/Scripts/jquery.dataTables.min.js" defer></script>
I ran into this error also. For whatever reason I had originally coded
var table = $('#myTable').DataTable({
"paging": false,
"order": [[ 4, "asc" ]]
});
This would not throw the error sometimes and other times it would. By changing code to
$('#myTable').DataTable({
"paging": false,
"order": [[ 4, "asc" ]]
});
Error appears to have stopped
In my case the solution was to delete cookies from the browser.
Having the same issue in Flask, I had already a template that loaded JQuery, Popper and Bootstrap. I was extending that template into other template that I was using as a base to load the page that had the table.
For some reason in Flask apparently the files in the outer template load before the files in the tables above in the hierarchy (the ones you are extending) so JQuery was loading before the DataTables files causing the issue.
I had to create another template where I run all my imports of JS CDNs in the same place, that solved the issue.
Sometimes it happens that the script (initializing of datatable) is embedded in a general page template, so if one of the pages that actually does not have any table and you did not import the jquery related files for datatable, you face this error, since the general initialization still is looking for that. (This was in my case)
Solution: Is to wrap the initialization of datatable inside a codition that check presence of the library before that:
Here is practical example of it.
if (typeof jQuery.fn.DataTable != "undefined"){
$('#accordionExample table').DataTable( {
"pageLength": 5,
"info": false,
"order": [[ 1, "desc" ]]
} );
}
This may also happen if you write Datatable instead of DataTable. (DataTable T must be capital). this is a beginner's mistake.
$(document).ready(function() {
$('#category-table').DataTable({
// Your Code
});
if you are sure that you aligned your scripts as described above, please make sure you DataTable word case is correct.
Before
$(document).ready(function() {
$('#myTable').Datatable();
});
After
$(document).ready(function() {
$('#myTable').DataTable();
});
small t is creating problem, when I changed this t to T it worked like a charm.

Change page on swipeleft/swiperight

I have problem with mobile/tablet version of page which I create
I need this: When someone look at product detail and move him to right/left (touch/swipe) then I need load next/previous product detail (= Example: Now I on page with id=2 when I go right, then I load page with id=3, npw I on page with id=3 and I go left then I load page with id=2.. etc.. with different pages id).
I look in thread here, but this solution is not dynamic and I have problem applicate it. Next I inspirated in W3C here.
Now I have these codes which not work:
JS file:
$(document).on('pageinit', function() {
$('.epicFullscreen').bind('swipeleft', function(event,ui)
{
$.mobile.changePage("http://www.some_domain.cz/category/page_name-1/","slide");
});
$('.epicFullscreen').bind('swiperight', function()
{
$.mobile.changePage("http://www.some_domain.cz/category/page_name-3/","slide");
});
});
$(document).on('pagehide', function () { $(this).off('swipeleft swiperight'); });
HTML:
<script src="funkce/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="funkce/jquery.mobile-1.3.2.min.js" type="text/javascript"></script>
<script src="funkce/skripty.js" type="text/javascript"></script>
I need use old JQuery 1.7.1. because this site using it and everything works fine, with newer JQuery I can have new problems. For that I use older JQuery-mobile 1.3.2. which must work with JQuery 1.7.1. ("jQuery Mobile 1.3 supports jQuery 1.7 and newer") . I can´t include "jquery.mobile-1.3.2.min.css" because this styles not work together with my styles correctly.
HTML in body is like that:
<div class="epicFullscreen">
<img class="epicImg" src="../../data_9/11normal.jpg" alt="inspirace č.2" title="inspirace č.2" border="0" />
</div>
Now I have dynamic solution with arrows (right/left) and with adding correct urls with PHP, but on tablet/mobile user like using touch not clicking on arrows etc...
=> Where I have problem and why not work my current solution? And how I can change this static JS to dynamic JS?
try this simple code .....
$(document).on("swipeleft", '#'+event.target.id, function () {
var nextpage = $(this).next('div[data-role="page"]');
if (nextpage.length > 0) {
alert(nextpage.attr('id'));
$.mobile.changePage(nextpage, "slide", false, true);
}
});
$(document).on("swiperight", '#'+event.target.id, function () {
var prevpage = $(this).prev('div[data-role="page"]');
if (prevpage.length > 0) {
$.mobile.changePage(prevpage, { transition: "slide", reverse: true }, true, true);
}
});
I found solution for that I make this answer. I simplify my problem and create simple page.
Code
<!DOCTYPE html>
<html>
<head>
<!--<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">-->
<script src="jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="jquery.mobile-1.3.2.min.js" type="text/javascript"></script>
<script>
$(document).on("pageinit",function(){
var pathname = $(location).attr('href');
var leva = $('#le').attr("href");
var prava = $('#pr').attr("href");
$("body").on("swiperight",function(){
<!--alert("You swiped right!");-->
location.href=prava;
});
$("body").on("swipeleft",function(){
<!--alert("You swiped left!");-->
location.href=leva;
});
});
</script>
</head>
<body>
<div id="test_div" style="display: block;">
<img src="test.gif" width="100px">
<a id="le" href="http://www.some_domain.cz/category/page_name-1/">left</a>
<a id="pr" href="http://www.some_domain.cz/category/page_name-3/">right</a>
</div>
</body>
</html>
I have this one hack - in PHP I know on which page I am, which page is before and which is next, I add this links it to arrows (which have tag "a"). This function working perfect. But I use this functional code to get correct URL => I don´t need some big function in JQuery which can split actual url with RegEx, know on which page I am, know if exist next page etc... Now I must only style this code to my page, but this is working.
I thank Omar for his time and I close this topic.

JQuery UI Dialog not found

I'm trying to implement the pop up contact us dialog in this tutorial:
http://www.matthidinger.com/archive/2011/02/22/Progressive-enhancement-tutorial-with-ASP-NET-MVC-3-and-jQuery.aspx
I have a working version of the solution that runs absolutely fine.
While trying to integrate this into my own solution I've ran into a problem.
I've created a contactdialog.js file in my scripts directory:
/// <reference path="jquery-1.6.2.min.js"/>
/// <reference path="jquery-ui-1.8.11.js"/>
$.ajaxSetup({ cache: false });
$(document).ready(function () {
$(".openDialog").live("click", function (e) {
e.preventDefault();
$("</div>")
.addClass("dialog")
.attr("id", $(this)
.attr("data-dialog-id"))
.appendTo("body")
.dialog({
title: $(this).attr("data-dialog-title"),
close: function () { $(this).remove() },
modal: true
})
.load(this.href);
});
$(".close").live("click", function (e) {
e.preventDefault();
$(this).closest(".dialog").dialog("close");
});
});
Then in my view I have near the top:
<script src="~/Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js" type="text/javascript"></script>
<script src="~/Scripts/jquery-ui-1.8.11.js" type="text/javascript"></script>
<script src="~/Scripts/contactdialog.js" type="text/javascript"></script>
And further down:
#Html.ActionLink("Contact Us", "ContactUs", "Home", null, new { #class = "openDialog", data_dialog_id = "emailDialog", data_dialog_title = "Contact Us"})
Now my link succesfully enters the javascript function, and seems to do the add class OK.
However when it gets to the .dialog function it throws the following exception:
"Object doesn't support property or method dialog"
Which would seem to indicate the jquery-UI hasn't been loaded.
However I can't figure out why?
If I load up the page in Chrome and check the page source the links to the jquery-ui-1.8.11.js happily open ok.
Some hints:
Is jqueryUI being loaded by another partial view (which is why you see it get loaded in developer tools) but the JS that calls .dialog is being rendered in a different partial view?
Try placing jqueryUI in the master/layout views?
I've changed to using bundling:
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/jqueryui")
#Scripts.Render("~/bundles/contact")
For reasons completely beyond me at present this has kicked it into life, and the dialog is now being presented!

ajax links getting mis-handled

I have an asp.net mvc 4 with jquery-mobile app.
On one page (url: /StatementBatch ), I have a list of batches, which are simply links to the batch details page (url: /StetementBatch/Details/4 ).
<li>
<a href="/StatementBatch/Details/4">
<h3>January 2012</h3>
<div style="float: right; width: 30%;"><strong>Issued : </strong>1/10/2012 12:00:00 AM</div>
<div style="float: right; width: 30%;">Completed</div>
<p class="ui-li-aside"><strong>1277</strong></p>
</a>
</li>
The oddity is that once the link is clicked, and the details page renders, the browsers current url is now http://localhost:49457/StatementBatch#/StatementBatch/Details/4
What do I need to change in the app to get this behavior fixed?
My guess is that its some sort of ajax loading related problem, but my shared _Layout.cshtml file contains $.mobile.ajaxEnabled = false;, which I expected would kill all ajax loading, but I've obviously mis-interpreted that one.
Thanks!
I suspect this may be the answer
jQuery Mobile ajaxEnabled doesn't work?
Will test and see if I can make it work
moving the mobileinit binding to after jquery, but before jquery-mobile does the trick. This appears to be a bug in MVC4's (new) mobile web application template, which simply bundles all the scripts together
This fails....
<link href="#System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" />
<script src="#System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Scripts/js")"></script>
<script>
$(document).bind("mobileinit", function() {
// As of Beta 2, jQuery Mobile's Ajax navigation does not work in all cases (e.g.,
// when navigating from a mobile to a non-mobile page, or when clicking "back"
// after a form post), hence disabling it.
$.mobile.ajaxEnabled = false;
});
</script>
But this works....
<link href="#System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.7.2.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.11.js" type="text/javascript"></script>
<script>
$(document).bind("mobileinit", function() {
// As of Beta 2, jQuery Mobile's Ajax navigation does not work in all cases (e.g.,
// when navigating from a mobile to a non-mobile page, or when clicking "back"
// after a form post), hence disabling it.
$.mobile.ajaxEnabled = false;
});
</script>
<script src="../../Scripts/jquery.mobile-1.1.0.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.unobtrusive-ajax.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script>
<script src="../../Scripts/modernizr-2.5.3.js" type="text/javascript"></script>
Thanks...
That is the default behaviour if you use jQuery mobile. jQuery mobile will enable all your links to be ajaxified. That means it will load content of the linked page via ajax and update the url. If you want to disable a link to be ajaxified, you can add rel attribute with external as value
This will open without ajax
This will do a normal page opening so your urls will updated based on the new page.
Alternatively you can use data-ajax="false" as well
This link also will open without ajax
this link has more info about it http://jquerymobile.com/test/docs/pages/page-links.html
That is strange. If $.mobile.ajaxEnabled = false; is set then it should not generate ajax links. Please check whether your view is using some other master page which has got this setting enabled. Look for "_ViewStart.cshtml" under the corresponding view directory to see which master it is linked to.
In order to disable Ajax behavior for a particular hyperlink use data-ajax="false" attribute. Like below
<a href="/StatementBatch/Details/4" data-ajax="false">
<h3>January 2012</h3>
<div style="float: right; width: 30%;"><strong>Issued : </strong>1/10/2012 12:00:00 AM</div>
<div style="float: right; width: 30%;">Completed</div>
<p class="ui-li-aside"><strong>1277</strong></p>
</a>

ASP .NET MVC - script reference inside partial view loaded by jQuery Ajax

Ok. I have this code to load my form:
$.ajax({
type: "GET",
url: "/Board/Post/QuickEditPost",
data: dataString,
success: function (data) {
$('#quick-edit-content').html(data);
}
});
$('#quick-edit-dialog').dialog('open');
It's working fine. Form is loaded, I can edit my post and so on.
But to make it fully functional I need:
<script src="#Url.Content("~/Scripts/tiny_mce/jquery.tinymce.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/tiny_mce/tiny_mce.js")" type="text/javascript"></script>
<script type="text/javascript">
tinyMCE.init({
theme: "advanced",
height: "450",
width: "600",
mode: "textareas"
});
Which is not loaded into jQueryUI dialog.
And my question is why is not loaded and how to overrride this behavior.I tried to put those references in head section, but that's not an real option, I need then in few specific places over entire application. Not to mention it doesn't work either.

Resources