Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi guys,

I am using asp.net mvc textboxfor like below
@Html.TextBoxFor(p => p.FirstName, new { data_ng_model="FirstName"})

from server i am filling model then assigning it to my view
FirstName="Some Name"

and in angular i assigned like below
$scope.FirstName=""


In my textbox i want to get "Some Name" and it should get assigned to $scope.FirstName as I am using it as angular model. but what actually happens is angular model overrides my server model value.
it show "" i.e. empty
Note: When I am not using angualr it works fine or when ever we assigned some to angular model like
$scope.FirstName="Other Name"
it shows "Other Name" in textbox.
Guys suggest me how to use angular model and TextBoxFor and angular model and TextBox should display server model value.


Thanks in advance.
Posted
Updated 8-Dec-14 23:35pm
v2
Comments
KUMPREK 9-Dec-14 6:25am    
Hey that's how MVC and angular works actually.
Because angular is something which runs on client side so it is overwriting the server side data in this case.

So you can try to assign the Firstname angular model variable with the server data. you can use something like @Model.FirstName to assign the variable.
Nathan Minier 9-Dec-14 7:15am    
You'd be better served populating the Controller values from a service that pulls JSON from your MVC, you can use $resource to keep it easy. Alternatively, you can set the textbox OnChanged to run an update function against your Angular Controller rather than straight binding the ng-model.

Personally, I'm of a mind that if you're going to do Angular, go all in and treat the server side of the stack as a data layer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900