2016-04-21 12 views
1

Ich habe diese tabset:Anruf mvc Url.Action von Winkelregler

<tabset justified="true" class="tabsetnowrap"> 
<tab ng-repeat="tab in tabshomepage track by $index" heading="{{tab.title}}" ng-click="homePageNavigate(tab.type)" active="tab.active" disabled="tab.disabled"> 
</tab> 

Es ist in einem Winkelregler erstellt:

$scope.tabshomepage = []; 
    $scope.tabshomepage.push(
    { title: 'Hjem', type: 'HOM', order: 1, active: true, disabled: false, color: 'black' }, 
    { title: 'Dirty', type: 'DIR', order: 2, active: false, disabled: false, color: 'purple' }, 
    { title: 'Dating', type: 'DAT', order: 3, active: false, disabled: false, color: 'green' }, 
    { title: 'Bloggers', type: 'SOC', order: 4, active: false, disabled: false, color: 'lblue' }, 
    { title: 'Konto', type: 'ACO', order: 5, active: false, disabled: false, color: 'black' }, 
    { title: 'Om os', type: 'ABU', order: 6, active: false, disabled: false, color: 'black' }, 
    { title: 'Kontakt og FAQ', type: 'COF', order: 7, active: false, disabled: false, color: 'black' } 
); 

Wenn ein Klick auf einen Reiter erfolgt , dann wird die homePageNavigate-Funktion ausgeführt.

$scope.homePageNavigate = function (type) { 
    if(type == 'DIR'){ 
     //Perform a @Url.Action("Index", "Dirty", null)" 
    } 
    etc... 
}; 

In diesem functin ich eine Mvc-Methode aufrufen wollen: @ Url.Action ("Index", "Dirty", null)“und geben einen Blick ("Index")

Was ist beste Weg, um dieses Problem zu lösen Problemumgehungen oder eine einfache Lösung für dieses

Antwort

4

ich vor etwas ähnliches getan haben durch ein wenig Konfiguration in Winkeldurchgeführt wird, durch Rasierer, auf Seite zu laden:?

<script> 
    (function() { 
     angular.module('App').value('paths', { 
      home: '@Url.Action("Index", "Dirty", null)' 
      // more paths here 
     }); 
    })(); 
</script> 

Dann können Sie injizieren und paths überall in Ihrer eckigen App verwenden. z. Innerhalb eines Controller namens 'myCtrl`

angular.module('App').controller('myCtrl', ['paths', function(paths) { 
    // you can use paths.home here 
}]); 
+0

In meinem Fall brauche ich das in der Steuerung. Ist es möglich, den Code für den Controller zu optimieren? – AHJ

+0

Sicher, es ist nur Standard-Winkeleinspritzung. – DrinkBird

+0

Danke. Ich werde das ausprobieren. Ich beziehe mich nur auf Instanz wie "paths.home" und sonst nichts? – AHJ

0

Es ist ganz einfach ASP.Net MVC-Controller Aktion-Methode unter Verwendung von AngularJS aufzurufen als

In Javascript folgt schrieb ich

var app = angular.module (' Meine App', []);

angular.module ('MeineAnw', [])

.Controller ('MyController' [ '$ scope', '$ http', function ($ Umfang, $ http) {

$ scope.search = function() {

$ http ({

Methode: "GET",

url: "/ home/GetData"

}). Dann (Funktion mySuccess (Antwort) {

$ scope.name = response.data;

} Funktion myError (response) {

$ scope.name = response.statusText;

});

}

}]); In HTML-Teil, ich

<button ng-click="search()">Get Data</button> 

In Controller Aktion schrieb, schrieb ich return Json ("Sie gefangen AngularJS", JsonRequestBehavior.AllowGet);