Missing model class when adding a view in ASP.NET MVC 3 - visual-studio-2010

In my ASP.NET MVC 3 project i have a reference to my DomainModel project.
The problem occurs when i try to create a strongly-typed view. In the model class list my models from the DomainModel doesn't exist.
I did the try the following with no success(From another thread):
-remove reference to the library containing the model
-clean project
-close VS
-reopen VS
-rebuild project (VS throws errors)
-re-add reference to the model library
-rebuild project
I also tried to update VS2010 to VS2010 SP1 same problem.
Any suggestion?

Well if you cannot see the model in the dialog box try to directlly call it from the view like this:
#model IEnumerable<Ieagle.WebSelfCare.Models.InvoicingIndex>
In case you have an IEnumerable Model otherwise
#model Ieagle.WebSelfCare.Models.Person
If you cant reach your models like this than you may have problems within the models

Related

Blazor components - namespace move

I am experiencing problem in VS 2022 in Blazor complex project. After moving Blazor components to different namespace/folder the components are not functional any more. My component does not 'recognize' other Blazor components anymore. For example custom component MudTable from MudBlazor namespace:
I would like to be able move Blazor components easily as simple classes.
Sometimes it helps to specify the same namespace in razor file to match namespace in partial code behind class, but sometimes I end up creating component (razor and cs files) with different name (copying the same code). This is very time consuming. I am not able to reproduce the described bug in Simple Projects. I have tried to reproduce the issue but it works fine (with minor VS bug) as described below. I will keep trying to reproduce the issue on Sample project.
Please find below scenarios working fine:
Simple scenario working fine
Steps to reproduce the issue:
Create Blazor Server App
Create folders
Components
Components\Sub1
Components\Sub2
Add new Razor component e.g. MyComponent1.razor to folder Components\Sub1
Verify that <MyComponent1\> works on some page. Eg. add lines to Index.razor:
#using BlazorApp1.Components.Sub1
<MyComponent1 />
Move MyComponent1.razor to folder Components\Sub2
Update Index.razor:
#using BlazorApp1.Components.Sub2
<MyComponent1 />
It works fine
More complex scenario with minor bug
Create Blazor Server App
Create folders
Components
Components\Sub1
Components\Sub2
Add new Razor component e.g. MyComponent1.razor to folder Components\Sub1
Add behind the class to 'MyComponent1.razor.cs' to folder Components\Sub1:
using Microsoft.AspNetCore.Components;
namespace BlazorApp1.Components.Sub1
{
public partial class MyComponent1:ComponentBase
{
}
}
Verify that <MyComponent1\> works on some page. Eg. add lines to Index.razor:
#using BlazorApp1.Components.Sub1
<MyComponent1 />
Rename folder Components\Sub1 to Components\Sub1Renamed.
Visual studio does not display any error and project can be compiled/started. Code behind is even displayed 'linked' to razor file:
This seems as a VS bug to me.
When project is started Component1 is invisible on Index page, because component 'BlazorApp1.Components.Sub1.Component1has no visual code defined, because it has only non-visual definition 'behind the code'. The file 'Component1.razor' with visual is not used at all because it is in unused namespaceBlazorApp1.Components.Sub1Renamed`
Update Index.razor:
#using BlazorApp1.Components.Sub1Renamed
<MyComponent1 />
When project is started, Component1 is visible on Index page (but I assume that no code behind is processed)
Do you have any hint, how to make it work for blazor components ?

I can't create a report with an object datasource in Visual studio 2019

I am trying to create a simple report in my vs2019 with a class as the data model
I have a public class named 'persona'
I have a new wpf applicacion (.net 5)
I've create a new report (RDLC file)
I try to use a class as a data template to design the report
When I try to reference the class as the data source object, the class is not visible for the datasourtce wizard as you can see in the image below
If put that class in a diferent project, a class library project, I got a different error, as you can see in the images below
And whe I press the Finish button I got this new erro:
There is no clue about what to do,... does anyone have any idea ? What Am I doing wrong?
I have same problem. Try to use netstandard2.0 for model library, it works for me (vs2019 netcoreapp3.1)

How to prevent a new controller from creating a new folder for its views in the Views folder?

I'm writing an ASP.NET MVC 5 application, where folders are organized by feature (ViewModels, Controllers, and Views are grouped together). I was able to override all default folder paths and manage all routing successfully. However, every time I create a new controller, Visual Studio creates a new Views folder and a child folder with controller name, which is a little bit annoying but that's fine.
Now, when I create another controller, I'm getting this error, because Visual Studio created the Views folder again, which is hidden now (excluded from the project). To fix this, I have to include the Views folder in the project and delete it after I create the controller.
Does anybody know any way to prevent this?
Error
There was an error running the selected code generator: 'A file or
folder with the name 'Views' already exists on disk at this location.
Please choose another name.
If this file or folder does not appear in the Solution Explorer, then
it is not currently part of your project. To view files which exist on
disk, but are not in the project, select Show All Files from the
Project menu.
Instead of using visual studio's Add -> Controller which generates the undesired view folder, create your controller using Add -> Class. Name the class conventionally with a Controller suffix and subclass Controller like this MyController : Controller.

2 times the same project in the Class View Window (visual studio)

After converting a Web Site Project to a Web Application Project in Visual Studio, it seems that there is a problem with some meta data. The first noticeable is the fact that the project is mentioned twice in the Class View window.
If I add a new namespace and a new class in it, I'm not able to select it using intellisense. when I open the hierarchy of the Class view, I see my new namespace in one of them (that are indentical except the recent addings)
Is there a way to clean that up ?
You have to get rid off the App Folder. That's the origin of this problem.
http://vishaljoshi.blogspot.be/2009/07/appcode-folder-doesnt-work-with-web.html

Can't Add Strongly-Typed View With Model From Referenced Assembly in ASP.NET MVC 3

I have a solution with an ASP.NET MVC 3 project, and a class library project. I created a reference to the class library, "Commands", in the web project, which is resolving; copy-local is also set to true and Commands.dll is being copied into the web project's bin directory.
When I try to add a strongly-typed view, selecting a class from Commands as the model, I receive a "Could not load file or assembly" error for the Commands assembly.
I've tried removing and re-adding the reference, cleaning and rebuilding the solution, etc. but still have the problem.
Something else odd about this is that when I click "Add view" in the controller to get to the add view dialog, the model in the referenced assembly is available in the "Model class:" drop-down.
Try using the Fully qualified name for the model class in your view.
Ex : #model YourClassLibraryNameSpace.YourClassname

Resources