How to use multiple model classes in one controller?

Posted by Chandu7x under ASP.NET MVC on 1/13/2014 | Points: 10 | Views : 1419 | Status : [Member] | Replies : 1

According to my requirement, i have created Model classes like Blocks,Slabs,CustDetails, CustFeedback, CustOrders classes .
Next i created context class for them.
Now i want to use all these classes in Home Controller.Is it possible?
Should i use multiple controllers for them?
Till now i know how to work with single model class in controller.Please suggest

My project is as given below.

There will be login page.

If Admin logged in ,then he can view total blocks and slabs.He can insert,update,delete blocks and slabs.He can view customers orders.He can view customer feedbacks.

If Customers logged in ,then he can view all blocks and slabs available.He can send an order to buy any desired block or slab .He can send feedback or complaints to admin.

My Database tables are:

Blocks,Slabs,CustDetails, CustFeedback, CustOrders .

I created model classes and context classes for them.How to use them in my Home controller.

Generally for single model class ,we do as below while creating controller

Controller Name: Home
Model Class: Block
Data Context Class: MyBlock

then how to do with multiple model classes? Please give me suggestions


Posted by: Kmandapalli on: 1/15/2014 [Member] Silver | Points: 25


You can have number of action result methods in a single controller.
So, obviously you can create number of views, or else you can even create partial views.
One method that i suggest is, when the user logs in, redirect him to a particular page(View).
In that view give him the links like slabs, blocks and so on..
When he clicks on the link, redirect him to that particular partial view.
When he clicks on the link, get the name of the link and based on it perform the binding.

Mark a answer if satisfied..

Shree M.

Kavya Shree Mandapalli

Chandu7x, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response