user3581934
user3581934

Reputation: 17

How to Get variable from MVC View to angular Controller?

I have this MVC application mix with angular. On Menu click we access this ClientController in server side 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 

Then i have this in my view ClientPartial.vbhtml

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

My angular controller is

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


enter code here

The problem is how can i get the StudentId in my angular controller?

Upvotes: 0

Views: 612

Answers (1)

Pascalz
Pascalz

Reputation: 2378

You can use ng-init

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

Upvotes: 1

Related Questions