1. What is the procedure to add a new method to the controller? Can I just write a method for the view or do I need to create the view first or vice versa? Is it more complicated than simply adding a new method with the same name as the view?
2. Is there a specific procedure for creating views or can I just add a view by copy pasting a currently existing one?
Create the action method in your controller first, then you can right-click anywhere in the code for the action method and select "Add View" from the context menu.
1)Add controller (Like ProgramController.cs) in controller folder and write action methods .In action methods you can also mention viewname if you want.
2) Add new folder (Like Program) in views Folder.
3) Add Program.aspx or ascx inside that Program folder
3) Add Program.aspx or ascx inside that Program folder
What do you mean add the view? I meant how do you add it? Is there a specific procedure that sets some internal routing properties? Is it just as simple as putting the file in there?
harrisrashee...
Member
237 Points
117 Posts
Adding a Method to a Controller and Creating Views
Jun 16, 2011 07:21 PM|LINK
Hi!
I was wondering...
1. What is the procedure to add a new method to the controller? Can I just write a method for the view or do I need to create the view first or vice versa? Is it more complicated than simply adding a new method with the same name as the view?
2. Is there a specific procedure for creating views or can I just add a view by copy pasting a currently existing one?
chohmann
Star
9385 Points
1644 Posts
Re: Adding a Method to a Controller and Creating Views
Jun 16, 2011 07:42 PM|LINK
Create the action method in your controller first, then you can right-click anywhere in the code for the action method and select "Add View" from the context menu.
harrisrashee...
Member
237 Points
117 Posts
Re: Adding a Method to a Controller and Creating Views
Jun 16, 2011 07:45 PM|LINK
I tried that approach but it didn't work because it doesn't say 'Add View'. I get the same context menu as before. Is it different for VS 2010?
chohmann
Star
9385 Points
1644 Posts
Re: Adding a Method to a Controller and Creating Views
Jun 16, 2011 07:47 PM|LINK
What version of Visual Studio are you using?
harrisrashee...
Member
237 Points
117 Posts
Re: Adding a Method to a Controller and Creating Views
Jun 16, 2011 07:51 PM|LINK
Visual Studio 2010 Pro
chohmann
Star
9385 Points
1644 Posts
Re: Adding a Method to a Controller and Creating Views
Jun 16, 2011 07:53 PM|LINK
Did you install MVC 3?
harrisrashee...
Member
237 Points
117 Posts
Re: Adding a Method to a Controller and Creating Views
Jun 16, 2011 07:56 PM|LINK
I am using MVC 2.
chohmann
Star
9385 Points
1644 Posts
Re: Adding a Method to a Controller and Creating Views
Jun 16, 2011 08:08 PM|LINK
Hmm? Even in MVC 2 the process was the same. Here's a link:
http://msdn.microsoft.com/en-us/library/dd410597.aspx
Can you compare the steps you took with the steps in that walkthrough and see if there are any differences?
Thulasiram
Member
444 Points
96 Posts
Re: Adding a Method to a Controller and Creating Views
Jun 16, 2011 08:11 PM|LINK
1)Add controller (Like ProgramController.cs) in controller folder and write action methods .In action methods you can also mention viewname if you want.
2) Add new folder (Like Program) in views Folder.
3) Add Program.aspx or ascx inside that Program folder
harrisrashee...
Member
237 Points
117 Posts
Re: Adding a Method to a Controller and Creating Views
Jun 16, 2011 08:12 PM|LINK
What do you mean add the view? I meant how do you add it? Is there a specific procedure that sets some internal routing properties? Is it just as simple as putting the file in there?