2015-08-21 122 views
0

我有這個MVC應用程序混合與角度。在菜單中點擊我們訪問此ClientController在服務器端MVC如何從MVC視圖獲取變量到角度控制器?

Partial Public Class ClientController 
Inherits System.Web.Mvc.Controller 

Function ClientPartial(ByVal id As Integer) As System.Web.Mvc.ActionResult 
    Dim student As ManagedForm(Of mmClientPartial) = utils.GetForm(Of mmClientPartial)(id)  
     Return PartialView("ClientPartial", student) 
    End Function 
End Class 

然後我在我看來ClientPartial.vbhtml有這個

<div ng-controller="studentController"> 
{{studentId}} 
</div> 

我的角度控制器

var mainApp = angular.module("mainApp", []); mainApp.controller('studentController', function ($scope) { 
$scope.studentId = "From MVC";}); 


enter code here 

的問題是我怎樣才能在我的角度控制器中獲得StudentId

回答

1

您可以使用ng-init

<div ng-controller="studentController" ng-init="[email protected]"> 
{{studentId}} 
</div> 
+0

的問題是,我需要這個studentId控制器加載dropdownControl'碼功能getcourse(){ \t回datacontext.getcourse(this.studentId)。然後(函數(data){ \t \t return vm.courselist = data; \t});所以我需要讓這個變量可用來加載下拉 – user3581934

+1

使用建議的方法非常合適,然後可以通過觀察對studentId控制器變量的更改來使用'watch'來加載de下拉。例如:$ scope。$ watch('studentId',function(newValue,oldValue){ if(newValue){ getCourse(newValue); } }); –

相關問題