I'm building out a view page and using an existing controller, so I just created the view. Now, I want to break it out so the view has it's own controller, is there a way to add a controller to an existing view?
A view works with an action method in the controller. You can create a controller and make an action method for the view, meaning the view.cshtml file name must match the action method name to tie them together.
If you find the post has answered your issue, then please mark post as 'answered'.
There is no way like we right click on Action Method of controller and create new view. But if you have form on your view and want to post then to specific controller action then use
is there a way to add a controller to an existing view?
One action corresponds to one view. For example, you have a existing view called Index.cshtml, the Action name should be Index, then they can match.
Best Regards,
Jiadong Meng
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
15 Points
278 Posts
add controller to existing view
Jan 14, 2020 02:20 PM|uid829402|LINK
I'm building out a view page and using an existing controller, so I just created the view. Now, I want to break it out so the view has it's own controller, is there a way to add a controller to an existing view?
Contributor
4963 Points
4213 Posts
Re: add controller to existing view
Jan 14, 2020 02:38 PM|DA924|LINK
A view works with an action method in the controller. You can create a controller and make an action method for the view, meaning the view.cshtml file name must match the action method name to tie them together.
Contributor
2340 Points
807 Posts
Re: add controller to existing view
Jan 14, 2020 04:50 PM|codemovement.pk|LINK
There is no way like we right click on Action Method of controller and create new view. But if you have form on your view and want to post then to specific controller action then use
Get more information: http://codemovement.pk
Thanks,
Participant
1320 Points
491 Posts
Re: add controller to existing view
Jan 15, 2020 03:34 AM|jiadongm|LINK
Hi IGotYourDotNet,
One action corresponds to one view. For example, you have a existing view called Index.cshtml, the Action name should be Index, then they can match.
Best Regards,
Jiadong Meng