I created a very very simple MVC view to show how many task are remaining in my todo list. Just as many tutorials out there but this time as an MVC auto hosted app.
I created the projects and played with the design a bit and everything was fun. But now I include the next code:
var context;
var web;
var user;
var list;
var listItems;
var listName = "QuickTasks";
$(document).ready(function () {
alert("starting ready function");
//get context and then username
context = new SP.ClientContext.get_current();
alert("context instantiated");
web = context.get_web();
alert("end of ready function");
//get the tasks for the user
//getTaskCountForUser();
});
The first alert is displayed, as a website triggered from SharePoint as soon as I start debugging and even when I start my developers subsite and it is shown as an app part. But the rest is not.
My main objective is to be able to get current user information from SharePoint context so I can then do stuff in my app. For example, print it on screen. I started via javascript but now I see there is a SharePointContext
class in the MVC, but no idea how to do that.
Additionally I have this script added in my view, besides those bundled by layout view.
<script src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.runtime.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.js" type="text/javascript"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.0/jquery-ui.min.js" type="text/javascript"></script>
<script src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-2.1.0.js" type="text/javascript"></script>