Visual Studio - Unable to find a matching view in MVC 4 - asp.net-mvc-4

I get this error when I right-click on controller action method and select 'Go to view'
This is in Visual Studio 2017.
i am pretty sure that I have the folders set up correctly in terms of naming conventions etc.
So I have an action method called 'Index' in 'MyMessagesController' within 'Controllers' folder.
And I have a view called 'Index.cshtml' within 'MyMessages' folder within 'Views' folder. The 'Views' folder is in same level as 'Controllers' folder.
Can anyone help me on this please.

So it was actually directory structure in the end. The structure is as follows:
So the controller I had was in MVCProject->MVC->Controllers.
The way it was mapped was that the view for it would be generated in MVCProject->Views.
But actually all the corresponding views were in MVCProject->MVC->Views and there was nothing in MVCProject->Views

Related

Intellij - Hide full path in Scopes view

I've started to use the Scopes view in Intelij, since the favorites got removed with the latest update (2021.3).
Somehow in the scopes view there is always the full folder path visible. In my example: below the folder test.foo.bar.baz there are the two folders test.foo.bar.baz.obj1 and test.foo.bar.baz.obj2. I would prefer to have below the folder test.foo.bar.baz only the two folder obj1 and obj2 as in the project view.
Scope View:
Project View:
Is it possible to make the Scopes view look like the Project view?
Thanks for your help!
Show Options Menu (it's the cog button at the top right of the Scope View) and disable Tree Appearance | Flatten Packages

How to have methods in common for several (partial) views

in my asp.net core web project i have two partial views that are displaying products. the first one shows them in a big layout, while the second one displays them in a smaller, regular layout.
both partial views need a method that composes a SEO-friendly url (using the product name and further information which are provided from the ViewModel). this method should somehow be accessible to the both views.
where can i place it inside of the asp.net core application? are there any particular conventions that must be followed?
#Html.Partial("ViewName")
Uses a view in current folder with this name. If none is found, searches the Shared folder
#Html.Partial("ViewName.cshtml")
A view with this name must be in the same folder
#Html.Partial("~/Views/Folder/ViewName.cshtml")
#Html.Partial("/Views/Folder/ViewName.cshtml")
Locate the view based on the application root. Paths that start with "/" or "~/" refer to the application root
#Html.Partial("../Account/LoginPartial.cshtml")
Locate the view using relative paths

Where to write ViewModel class in MVC4

I have one doubt that where to write ViewModel class in MVC4. I could see that there is two folder called Models and ViewModel. In case of writing parentmodel and viewmodel class, under which folder i have to write it.
My suggestion is to create a ViewModels folder and keep all view-models in it by creating hierarchy same as your Views folder in it.
Like suppose you have Index.cshtml and About.cshtml in
View -> Home
folder, then put the view-models defined for Index and About in
ViewModels -> Home -> IndexViewModel.cs
and
ViewModels -> Home -> AboutViewModel.cs
This helps to keep code separation in development.
I hope you got an idea. Thank you.
Ultimately its up to preference. Im quite new to MVC but i like to keep my models and ViewModels in one place (if its not a huge project!) that way the file paths are similar and easier to keep a track of. If it's a view model i just like to put ViewModel at the end of the name. For e.g:
UserViewModel.cs / UserVM.cs (your view models)
User.cs(just a regular model)
If it's a big project where you have lots of both, it's quite acceptable to put them all in a different project all together, again keeping your file paths accessible.

SiteController cannot find the requested view

I am new to YII framework.I have installed Yii framework and I created one new sample project.
by default one sample application is coming. I am trying to add one new page to that site. i have created one new tab in menu. I copied that file to view folder.
when I click that tab in menu I got bellow error.
SiteController cannot find the requested view "adddep".
C:\xampp\Yii\framework\web\CController.php(878)
please any one can help me to solve this problem.
Thanks,
DHamodhar.E
The file adddep.php should be under views/site folder.
you say copy file to view folder and add a menu tab, you must follow mvc structure,
If you only create view file then you must need to create controller file, its not directly hit view file, first its hit controller file
here some tutorial link:
http://www.yiiframework.com/screencasts/
http://www.yiiframework.com/tutorials/

how to share pariail templates in different modules

for example, I hava a partial template named _header.php, I want to use it in both Post, Forum module, How can i write renderPartial(), to load this template.
placed your partial view to app layouts dir.
<?php
$this->renderPartial('//_header.php');
?>
absolute view within a module:
the view name starts with a single slash '/'. In this case, the view will be searched for under the currently active module's view path. If there is no active module, the view will be searched for under the application's view path.
absolute view within the application:
the view name starts with double slashes '//'. In this case, the view will be searched for under the application's view path. This syntax has been available since version 1.1.3.
reference getViewFile()