Get Connected!

Come and join our community. Expand your network and get to know new people!

Ganesh replied to the topic 'How to filter data in controller using asp.net mvc' in the forum. 2 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. 2 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. 2 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. 2 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...

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

There are three ways to pass data from Controller to View:
VIEWDATA
VIEWBAG
Model

Read More...

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

Inside the class, we can create properties. Few examples of properties are :

public string UserName { get; set; }

public string Password { get; set; }

public long MobileNumber { get; set; }

public DateTime DateofBirth { get; set; }

public bool Indian { get; set; }

Read More...

Sreevani replied to the topic 'How to create Views in Asp.Net MVC' in the forum. 2 months ago

To create View:

Step 1: Right click on the default view named 'Index' and select Add View.



Step 2: Now give the View name as "Login" and then select Template as 'Create'.



Step 3: Select Model class as your Class Name "MyClass".



Step 4: Clickk on Add.



Step 5: Now the view is created in the Views folder.



View Code looks like:



Read More...

Sreevani replied to the topic 'How to create controller in Asp.Net MVC' in the forum. 2 months ago

What is Controller?
Asp.net MVC Controllers are responsible for controlling the flow of the application execution. When you make a request to MVC applications, a controller is responsible for returning the response to that request. A controller can have one or more actions. A controller action can return different types of action results to a particular request.

Creating a Controller:

After creating new Asp.net MVC project and Model with required properties we have to create Controller.
Step 1: In Solution Explorer, right-click on the Controllers folder and select the option Add and then Controller.



Step 2: After selecting the 'Add Controller', dialog box is being displayed. In that Add Scaffold dialog box, click 'MVC 5 Controller - Empty', and then click Add.



Step 3: Name your new controller as "MyFirstController".



Step 4: Now the New Controller is created under Controllers folder.



Read More...

.Chandra(Admin) created a new topic ' How to validata forms developed with asp.net mvc' in the forum. 2 months ago

How to validata forms developed with asp.net mvc

Read More...

.Chandra(Admin) created a new topic ' How to filter data in controller using asp.net mvc' in the forum. 2 months ago

How to filter data in controller using asp.net mvc

Read More...

How to read table data from data base in controller using asp.net mvc

Read More...

.Chandra(Admin) created a new topic ' how to create ado.net entity model' in the forum. 2 months ago

how to create ado.net entity model in steps?

Read More...

How to pass data from UI to Controller using asp.net mvc in steps

Read More...

How can I create a simple register form with asp.net mvc in steps

Read More...

.Chandra(Admin) created a new topic ' How to pass data from controller to view' in the forum. 2 months ago

Can you give one example on how to pass data from controller to view.

Read More...

Can you gove some examples on how to create properties

Read More...

.Chandra(Admin) created a new topic ' How to create Views in Asp.Net MVC' in the forum. 2 months ago

How to create Views in Asp.Net MVC in steps

Read More...

.Chandra(Admin) created a new topic ' How to create controller in Asp.Net MVC' in the forum. 2 months ago

How do we create controller in Asp.Net MVC in steps

Read More...

.Chandra(Admin) is friends with Gopal Reddy