Access the Model in the PartialView from RenderAction - javascript

Is it possible to access the model in the PartialView returned by RenderAction from the parent view?
I have a controller action that returns a view with a list of items that have geographical data. I'd like to use the lat/lon to place the items on a map as well, but I don't want to have to parse the html for the data.

Related

I want to store changeable data within one column of my table row

So, I have a vue component called stats. Basically how its stored is it has a name for example: 'goals'. It fetches the row with the id/name of 'goals' from the database and the point is to access the info column within that to fetch specific data.
This is how the row would look
ID Name Info Created_at Updated_at
"1" "user" "{"goal": 1,"current":500}" "2019-04-28 03:54:44" "2019-04-28 03:54:46"
I want to be able to access the data within the Info column and display it accordingly. I can't seem how to get it working though within javascript.
This is how i call it
axios.get('/api/stats/user').then((res) => {this.test = res.data; console.log(this.test)});
and in the console i get the object i want but info looks like this:
info: "{"goal": 1000, "current":500}"
and I can't seem to be able to grab it by ['goal'] or this.test.info.goal which is what I want
First of all, create a resource file for yor model and create an accessor for your info/goal field.
You should use the resource files for each json response which contains models/collection of models.
This way you can modify what to display in your json response about each model.

exposing angularjs grid data from one controller into another

I'm trying to push data from a link within my grid data UI, when you click the link, open a popup (which I do with a modal fine) however when the modal opens, I can't access any of the data that was defined in the other controller.
This snippet:
<a href ng-click="grid.appScope[col.field](row.entity)">Popup</a>
Works fine, where it shows the col.field value, however I'd like to show data within the popup from grid.appScopecol.field in the popup - however that is another controller, how would I handle passing data from one controller to another within this format?
My suggestion is just pass those data into angular service define a service like
angular.service('MyService', function() {
//if you want Object format or
this.controller1Data = {};
//if you want array format
this.controller1Data = {};
});
in your controller just pass the data into that service like
//In controller
MyService.controller1Data = //Pass the data to that service;
then in HTMl
<a href ng-click="//call that method()">Popup</a>

Angular select multiple not refreshing on model change

I have the following issue with angular and the html select-input:
When the user loads the page my select is empty until the data is loaded and returned from the corresponding service.
In this case the select is populated correctly.
However, the user should be able to filter the model with a click on a button.
When I press the button a new request is send to the REST-API and the response contains the new model for the select.
Unfortunately, the select won't update correctly even when I change it's model
Here is some code to illustrate my problem:
// This happens in my controller
EventService.getAvailableRooms(requestObject).then(function successCallback(response){
// sanatizeRoomTypes is used to generate user-friendly names instead of [1, 2,..]
vm.rooms = DataSanatizer.sanatizeRoomTypes(response.data);
}, function errorCallback(response){
console.log(response)
});
vm.rooms is the model of my select:
<select id="roomSelect" ng-model="eventCtrl.selectedRooms"
ng-options="room.name group by room.type for room in eventCtrl.rooms track by room.id" multiple required>
</select>
In some cases the select duplicates it's model or looses entries. It seems like there is some sort of data binding problem.
Thanks,
Try wrapping your model changes in $scope.apply :
$scope.$apply(function() {
$scope.data.myVar = "Another value";
});
Read here for more info:
http://tutorials.jenkov.com/angularjs/watch-digest-apply.html
You can also use $scope.$watch on the changing $scope variables to update them in your view.

see model data from controller in View [sap ui5]

I've created a JSON model in a controller, and I have nice data list there...
but I do not know how to access this list/model via corresponding view. Help?
You can set model in controller:
`sap.ui.getCore().setModel(jsonModel,"NAME");`
and get this model in View (JS view) with:
`sap.ui.getCore().getModel("NAME");`

How to bind Knockout.js to existing table grid?

I'm a newbie to Knockout.js. I implemented the Knockout.js by loading data from ajax source and use foreach loop to create a table of the data. The tutorial i followed is here
http://www.dotnetcurry.com/ShowArticle.aspx?ID=933
My issue here is, due to the nature of my application, I find that the first load is better served from the server side using a grid component and I only want Knockout.js to take care of "Add" row, "Update" a row and "delete" a row.
My question is,
1) how do I replace the "first" load and populate the lookupCollection :ko.observableArray() in the article with the default data in the html table?
2) Related to #1. If the first load, the table layout with data is constructed from the server side, then how do I bind "foreach" to the grid so "add" can be performed on lookupCollection?
Thanks and again, I'm a newbie, I must be missing some key concepts here.
One way would be to pass your initial data into your view model. Since you are using asp.net it would look something like this:
//Dump raw data into javascript variable
var data = #Html.Raw(ViewBag.Data);
function ViewModel(data) {
var self = this;
//Unpack raw data
self.lookupCollection = ko.observableArray(data.lookupCollection);
}
//initialize view model
var viewModel = new ViewModel(data);
ko.applyBindings(viewModel);

Categories

Resources