Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this work with Razor views? #6796

Closed
danieljsummers opened this issue Jun 1, 2018 — with docs.microsoft.com · 19 comments
Closed

Does this work with Razor views? #6796

danieljsummers opened this issue Jun 1, 2018 — with docs.microsoft.com · 19 comments
Assignees
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue
Milestone

Comments

Copy link
Contributor

This is a feature I've been wanting for quite some time. :) I've been trying to make it work by providing Razor views for use in an MVC application, but I'm having trouble getting that to work. From the description, it seems like it should work; am I reading correctly?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@Rick-Anderson Rick-Anderson self-assigned this Jun 1, 2018
@Rick-Anderson Rick-Anderson added Source - Docs.ms Docs Customer feedback via GitHub Issue P4 labels Jun 1, 2018
@Rick-Anderson Rick-Anderson added this to the Backlog milestone Jun 1, 2018
@Rick-Anderson
Copy link
Contributor

@danieljsummers
Copy link
Contributor Author

Thanks for the quick reply! The examples in that document, though, are also for "Razor Pages". What I was trying to do was put a cshtml file in the library (under Home/Test.cshtml), then use a regular controller (in my example HomeController, action Test which is a simple call to View()) to utilize the view in the library.

I guess the question would be better asked "Does this only work for Razor files with an @page directive?"

@rahamohebbi
Copy link

rahamohebbi commented Jun 1, 2018

Similar to @danieljsummers I can't get the RCL to work with View Component. I am getting an error saying that the view can't be found. I created a view component the way I usually do and added a view under Views/Shared/Components in the RCL project.

The documentation is saying that RCL is suitable for view components and MVC style Razor pages. Is there an example for this ?

@Rick-Anderson This is the folder structure for my RCL project. Nothing fancy. I added a reference to my MVC project that is consuming this class library. Based on my folder structure if there anything that I need to do to tell the MVC project where to look for the view ?
Note: I successfully added the view component to the page and it can find the assembly, It even go to the constructor but it only fails when it tries to find the actual razor view.

folder-structor

@Rick-Anderson
Copy link
Contributor

@rahamohebbi create the simplest possible project that reproduces the problem and I'll see if I can get someone to look at it. I know it works with view components though.

@danieljsummers
Copy link
Contributor Author

I've tried several different spots, but still can't make it. I've made a repro of it with 4 different patterns, none of which work.

(This is low priority; I'm sure it's something I'm doing wrong, and I truly do appreciate the help.)

@danieljsummers
Copy link
Contributor Author

BTW, I'd also be willing to strip it down further (remove JS and all that) and make a similar example as the one with the pages.

@Rick-Anderson
Copy link
Contributor

@pranavkm can you comment on problems with VC's in RCLs?

@Rick-Anderson
Copy link
Contributor

ASP.NET Core discovers view components from all registered application parts and ViewComponent views should compile along with other views in the project just fine.

@pranavkm
Copy link
Contributor

pranavkm commented Jun 1, 2018

@danieljsummers - try changing the name of your secondary project. The file name that the class library Rcl.Views produces collides with the Views dll that the RazorSdk produces for the Rcl project.

@rahamohebbi a repro app would help.

@danieljsummers
Copy link
Contributor Author

@pranavkm That's it! :) Works like a charm now.

Would this page be the right place for a warning about this? I'll do up a PR if so.

@rahamohebbi
Copy link

rahamohebbi commented Jun 2, 2018

@Rick-Anderson @pranavkm thanks
I created a brand new asp net core application and added a brand new class library (RCL). everything worked really well so started digging a little more comparing it with my main application.

The only difference i noticed was the RCL project file. copy pasted it to my existing class library and everything worked as it should. We might have some bugs there that needs to be ironed out.

Cheers

@Rick-Anderson
Copy link
Contributor

@rahamohebbi thanks for the update.

@Rick-Anderson
Copy link
Contributor

@pranavkm can you respond to @danieljsummers

Would this page be the right place for a warning about this? I'll do up a PR if so.

Is that worth warning about?

@danieljsummers
Copy link
Contributor Author

While you're considering it, my thoughts were, under the "Create a class library containing Razor UI" heading:

  • On the "Visual Studio" tab, adding a bullet before the last one, saying something like "Name the library (ex. "RazorUIClassLib"). (Ensure the name does not end with .Views to avoid a namespace collision.)"
  • On the .NET Core CLI tab, adding the same italicized text after the link that provides the link to documentation for dotnet new.

OTOH, if the namespace collision shouldn't be an issue (i.e., a bug), then I'd think the doc either wouldn't need to be updated, or could be updated now, and then reverted once the fix is in place.

@Rick-Anderson
Copy link
Contributor

@pranavkm can you comment on the suggestion by @danieljsummers ?

@pranavkm
Copy link
Contributor

pranavkm commented Jun 3, 2018

This seems reasonable. Also, it's an issue with file name collision rather than a namespace collision.

@danieljsummers
Copy link
Contributor Author

I'll get it turned tomorrow evening (Sunday) unless something comes up IRL.

@danieljsummers
Copy link
Contributor Author

I ended up moving the bullet up 1 from my original suggestion, because the name of the project precedes the dialog that has the .NET Core 2.1 selection. I also spelled out "filename collision with the generated view library" vs. "namespace collision".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

4 participants