Ich versuche Contoller Aktionsmethode mit Angularjs aufrufen. Folgendes ist mein Ansichtscode.
@using DotNetNuke.Framework.JavaScriptLibraries
@using DotNetNuke.Web.Client.ClientResourceManagement
@{
ViewBag.Title = "Index";
ClientResourceManager.RegisterScript(Dnn.DnnPage, "~/desktopmodules/mvc/DNNMVCModule/Scripts/angular.js");
ClientResourceManager.RegisterScript(Dnn.DnnPage, "~/desktopmodules/mvc/DNNMVCModule/Scripts/DnnMvcModule.js");
}
<h2 >DnnMvcModule Index</h2>
<div id="Testdiv" ng-app="dataStore" >
<div ng-controller="StoreController as store">
<h3>{{data.name}}</h3>
<h3>{{data.surname}}</h3>
</div>
</div>
Herer ist mein eckiger js-Code.
(function() {
var app = angular.module('dataStore', []);
app.controller('StoreController', function ($scope, $http) {
$http.get('/DnnMvcModule/GetData').
success(function (response, status) {
$scope.data = response;
alert(data.name);
}).
error(function (response, status, headers, config) {
$scope.data = response;
alert(data.cod);
});
});
})();
Hier ist die Aktionsmethode meines Contollers.
Als ich versucht habe, die GetData-Methode des Controllers mit dem obigen Code als Antwort aufzurufen, erhalte ich das folgende Fehlerformular DNN.
Error: DNNMVCModule is currently unavailable.
\r\n DotNetNuke.Services.Exceptions.ModuleLoadException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.
\r\n at DotNetNuke.Web.Mvc.Routing.StandardModuleRoutingProvider.GetRouteData(HttpContextBase httpContext, ModuleControlInfo moduleControl)
\r\n at DotNetNuke.Web.Mvc.MvcHostControl.GetModuleRequestContext(HttpContextBase httpContext)\r\n at DotNetNuke.Web.Mvc.MvcHostControl.OnInit(EventArgs e)
\r\n --- End of inner exception stack trace ---\r\n\r\n\t
Das gleiche habe ich mit normalen MVC-Anwendung ausprobiert funktioniert es gut. Kann mir jemand helfen, was schief läuft?!?
HI Mitchel, Danke für die Antwort. Ich habe Chris Hammonds MVC DNN 8 Vorlage verwendet, um dieses Projekt zu erstellen, und es gibt keine Routerkonfigurationsdatei in dieser Vorlage. So wie wir es in nomalen MVC-Anwendungsprojektschablonen haben. und es gibt keine Global.asax-Datei. :( – user1331438