Ganesh replied to the topic 'How to filter data in controller using asp.net mvc' in the forum. 5 months ago

LINQ (Language Integrated Query) is used to filter data in Controller. This can be used on a list or an array object.

Some of the methods used are - Select, Where, OrderBy, etc.

Example to fetch student names in ascending order whose age is greater than 15.

var filteredData = students.Where(x => x.Age > 15).Select(x => x.Name).OrderBy(x => x.Name).ToList();

Read More...

Ganesh replied to the topic 'How to validata forms developed with asp.net mvc' in the forum. 5 months ago

Forms validation can be achieved using the below attributes which can be set on the Model properties.

Multiple attributes can be applied on a single property.

public class OrderItem
{
[Required]
public string Name { get; set; }

[DisplayName("Item Price")]
[DataType(DataType.Currency)]
public decimal Price { get; set; }
}

Read More...

Ganesh replied to the topic 'Can you gove some examples on how to create properties' in the forum. 5 months ago

Properties are members that are used to store and get values. It has get and set methods. Logic can be written within this as well.

Properties can be written for any number of variables of any data types. Set method gets the caller data using the variable named "value".

Example 1 :
public string Name
{
get { }
set { }
}

Example 2 :
private int _age;
public int Age
{
get { return _age; }
set { _age = value; }
}

Read More...

Ganesh replied to the topic 'How to pass data from controller to view' in the forum. 5 months ago

Views are displayed as HTML pages via our .CSHTML / .VBHTML files.

We can make use of below options to pass data from our Controller (Business logic) to View (UI)

a) ViewData
b) ViewBag

Example code in Controller :
ViewData["MyName"] = "Ganesh";

Example code to receive in View :
<p>@ViewData["MyName"]</p>

Read More...

Ganesh replied to the topic 'Feedback on Noncommercial activities by HyderabadTechies' in the forum. 6 months ago

Hi Chandra,

This is a wonderful activity and I'm happy that I got an opportunity to attend it.

And this is a good source for beginners and interested learners. Learning curve is good here with real time scenarios well explained and illustrated with practical examples. And the daily knowledge refresh session, surprise quiz were also amazing.

Wish you a great success for all your upcoming activity / events and I'll be attending it :)

Maintain the same pace.

Read More...

Ganesh replied to the topic 'How can I create a simple directive?' in the forum. 6 months ago

Directives can be created in similar way to create controllers. Below is an example.

var app = angular.module("MyModule", []);
app.Controller("MyController", function ()
{
// Your initializers goes here.
});

// Always use camel-case for directive names
app.directive("myHeader", function() {
return {
template : "<h2>Hello.. Welcome to my page !!</h2>";
}
});

Below is the code to use the directive in HTML UI.

<body ng-app="MyModule" ng-controller="MyController">
Option 1 : <div my-header></div>
Option 2 : <my-header></my-header>
Option 3 : <div class="my-header"></div>
Option 4 : <!-- directive: my-header -->
</body>

Above example shows 4 different options to use your custom directive. This example will print the header 4 times.

Read More...

Services can be created in similar way to create controllers. Below is an example.

var app = angular.module("MyModule", []);
app.Controller("MyController", function ()
{
// Your initializers goes here.
$scope.students = [];
});

app.Service("StudentService", function ()
{
$http.get("https://localhost/getstudentsinfo")
.then(function (response)
{
$scope.students = response;
},
function (errorResponse)
{
// Handle errors here.
}
);
});

Read More...

Ganesh has a new avatar. 6 months ago
Ganesh replied to the topic 'How to create functions in AngularJS' in the forum. 6 months ago

Functions in AngularJS can be created within the Controller.

Below is sample code to create a function and pass a parameter to it.

<script>
var app = angular.module('myModule', []);
app.controller("myController", function ($scope) {
$scope.MyFunction = function () {
alert('Welcome');
};
});
</script>

Read More...

Ganesh replied to the topic 'How to Create function and pass parameter to it?' in the forum. 6 months ago

Below is sample code to create a function and pass a parameter to it.

<script>
var app = angular.module('myModule', []);
app.controller("myController", function ($scope) {
$scope.MyFunction = function (data) {
// Make use of data variable here !!
};
});
</script>

Below is the code to invoke the function.

<body ng-app="myModule" ng-controller="myController">
<input type=button value="Click me" ng-click="MyFunction('Hi.. Welcome')" />
</body>

Read More...