I use MVC razor to render the model below.
@Html.HiddenFor(u => u.FormNo, new { @ng_model = "formData.formno" })
When source code is viewed, the html input has a value.
<input id="FormNum" name="FormNum" ng-model="formData.formno" type="text" value="154S00017">
but angular returns this as a blank value in the controller.
var url;
var controller = 'Inbox';
var action = 'Get_RCTS_FormHistory';
var RCTS = angular.module('RCTS', []);
RCTS.controller('historyController', function ($scope, $http) {
$scope.formData = {};
$scope.formData.formno = '';
url = "/" + controller + "/" + action + "?FormNo=" + $scope.formData.formno;
alert(url)
$http.get(url).success(function (data) {
$scope.logs = data;
});
});
And when debugged in Visual studio.
I'm fairly new to angular and this really irritates me. I tried adding a document.ready() function there on the controller but it also returned an error.
Thanks
I resolved this by assigning the value from another html input.
$scope.formData.formno = $('#FormNo').val();
and ultimately resolved it by using
@Html.HiddenFor(u => u.FormNo, new { @ng_model = "formData.formno",@ng_init=@Model.FormNo })
from Razor view.