如何从我的C#代码隐藏文件修改角度ng模型?

时间:2014-08-14 22:17:35

标签: c# javascript asp.net angularjs episerver

问题是,如果我将指令ng-model添加到我的任何asp:TextBox中,那么我就无法从我的代码隐藏文件中更改它们的值。 ng-model与vm.Company绑定,我无法从我的代码后面访问。我会在javascript中完成所有操作,但我不知道如何在.NET之外获取EPiServerProfile.current。

用户控制(.ascx):

<div class="container" data-ng-app="app">
    <div data-ng-controller="membershipsettingscontrol as vm" class="row">
        <div class="row">
            <div class="span4">
                <label for="txtCompanyName">Company Name:</label>
            </div>
            <div class="span8">
                <asp:TextBox runat="server" ID="txtCompanyName" data-ng-model="vm.Company" data-ng-disabled="false" />
            </div>
        </div>
     </div>
 </div>

我的代码隐藏文件(.cs):

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                currentProfile = EPiServerProfile.Current;
                txtCompanyName.Text = currentProfile.Company;
            }
        }

app.js:

(function () {
    'use strict';
    var controllerId = 'membershipsettingscontrol';
    angular.module('app').controller(controllerId, ['$scope', '$location', 'datacontext.sbcountry', 'datacontext.sbstates', 'datacontext.sbcontact', admin]);

    function admin($scope, $location, sbcountrydatacontext, sbstatesdatacontext, sbcontactdatacontext) {
        var vm = this;
        vm.title = 'Job Add';

        vm.states = [];
        vm.Address = {};

        vm.getStates = getStates;
        vm.submit = submit;

        getCountries();
        pageLoad();

        function getCountries() {
            return sbcountrydatacontext.getCountries().then(function (httpResults) {
                vm.countries = httpResults.data.Countries;
            });
        }

        function getStates(country) {
            return sbstatesdatacontext.getStates(country).then(function (httpResults) {
                vm.states = httpResults.data.States;
            });
        }

        function submit(data) {
            return sbcontactdatacontext.updateContact(data);
        }


    }
})();

0 个答案:

没有答案