Xamarin razor template inherit breaks Intellisense in editor - razor

When using #inherits in a razor template view in portable library for a Xamarin-based hybrid app, the intellisense is broken such that it red-underlines the functions provided by the base view class such as "#Model". I have a fresh update of the Xamarin tools (4.1.0.530).
The first fix here doesn't apply: Xamarin WebView - No Intellisense in razor
I'm not sure if this is related, but the RazorTemplateProcessor doesn't seem to be reading my web.config such that I also have to reference class names fully qualified, or the generated code-behind file will have a compile error. How to get it to support web.config?

Related

Adding a razor page in Blazor Project creates a .cshtml file

I'm following a tutorial trying to create a blazor project.
It says to add a razor page. When I right click on Pages folder ->Add->Razor Page, I get this prompt.
No matter what options I pick, the new file is a .cshtml file, not a .razor file.
I see other .razor files in the same folder by default.
Target Framework: .NET Core 3.1
Am I missing something?
I'm using Microsoft Visual Studio Professional 2019, Version 16.4.3.
Instead of creating a new "Blazor Page", go to the dialog to add a "New Item". From ASP.NET Core, Select "Blazor Component". This will create a new file called YourComponent.razor.
Bonus Fact: To create a code-behind file for the component, add a new class and specify the name YourComponent.razor.cs. Declare the class partial (because the .razor file itself makes a partial class declaration).
I am also new to Blazor and this has been a source of confusion for me. I hope that they make it more straight-forward in the next version of Visual Studio.

Razor Class Library in ASP .Net Core 2.1.1

I used to embed some of my Razor views for mailing in a class library which was using ASP .Net Core 2.1.0-preview1-final and it was working fine.
Here is the configuration in the .csproj file:
Since I upgraded the .Net Core version to 2.1.1 which is the final one, I can not use the embedded views anymore.
I know about the new Razor Class Library concept but I need to pass my views to a ViewRenderer service which basically converts the view to string to be sent as an email.
The viewrenderer service was finding the views before but now it doesn't find them and I get the following error:
VIEW does not match any available view
How can I fix this issue?
I was facing the exact same issue, setting CopyRefAssembliesToPublishDirectory to true in the csproj file fixed it. your csproj file should look like this :
...
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<CopyRefAssembliesToPublishDirectory>true</CopyRefAssembliesToPublishDirectory>
</PropertyGroup>
...

can I use Kendo UI Grid with Nuget package Telerik.UI.for.AspNet.Core?

I am running into a strange issue. I built an ASP.net Razor project with a Kendo UI Grid. When I first built it, I made a direct reference to the Kendo.Mvc.dll, and all was good. But I need it to be referenced by a NuGet package. However, when I switch the reference, it no longer recognizes Html.Kendo().Grid. I have tried moving the namespace reference from the Views/Web.config to the main web.config as well, but no luck. The error message I get is:
Compiler Error Message: CS1061: 'HtmlHelper' does not contain a definition for 'Kendo' and no extension method 'Kendo' accepting a first argument of type 'HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
Is it possible that something in the larger NuGet Telerik.UI.for.AspNet.Core package is overriding something in the base Kendo.Mvc.dll? Or does my namespace need to be moved somewhere else? Any help would be appreciated.
Kendo UI Core does not include certain widgets, the Grid being one of them, nor does it include the server side wrappers so the Razor helpers such as Html.Kendo().Grid will not work. Hence using the Core package available via NuGet cannot be used for what you need. So the simple answer to your question is, unfortunately, no.

ServiceStack Razor Intellisense not working in SelfHost

I have ServiceStack.Razor referenced.
Following razor file works great:
#model ServiceStack.Host.Operation
#Model.Name
but IntelliSense (and R# code analysis) shows error: "Cannot resolve symbol 'model'"
Referencing Microsoft.AspNet.Mvc makes Intellisense work, but Razor pages are not compiled.
This is because ServiceStack.Razor contains System.Web.Razor assembly version 3.0.0 and Microsoft.AspNet.Mvc requires a 3.2.3, one is overwritten by other and assembly load exceptions occur.
Tried to follow this answer:
ServiceStack turn on Razor intellisense support without MVC
and add Web.config but this gives me different error:
"Cannot access private field 'model' here"
How to make Intellisense work without breaking application?
Unfortunately VS.NET 2015 designer doesn't properly support editing Razor pages in Self-Host (i.e. non ASP.NET Projects) so you wont be able to get rid of all the designer errors, although you can minimize the issues by first adding a Web.config with the Razor configuration, here's a Web.config template you can use, you'll need to replace $safeprojectname$ with the namespace of your project. The Web.config have no effect to the behavior of non Web projects, it's just use to provide hints to VS.NET intellisense which is coupled to ASP.NET Web projects.
Instead of #model you'll want to use the more explicit:
#inherits ViewPage<ServiceStack.Host.Operation>
These both do the same thing, but the designer is happier with the explicit #inherits.

Nancy: Razor View Engine #using IntelliSense not working

I have an IntelliSense problem with Nancy and the Razor View Engine.
I try to use the functionality of an (self-made) external library inside my razor view. Therefore I reference the dll and try to put an #using and the namespace on top of the view to get some IntelliSense-Support.
But it doesn't work. The #using can't find the dll or rather the namespace I have to put behind it.
The VS-Error I get is: "The type or namespace name 'type/namespace' could not be found (are you missing a using directive or an assembly reference?)"
It just seems to be an IntelliSense problem because the engine is able to render the view if I use the correct #using on top of the view and ignore the error message or if I have a class inside my project which inherits from IRazorConfiguration and returns the needed namespace.
Notes:
Hosting: Self-Host and/or OWIN
It works if the library is part of the same solution
This happens with with Nancy 0.22.2 as well as 0.23 and the corresponding Razor packages.
Steps to reproduce (or better: things I did):
Create a new Console Application
Install the Nancy Razor View Engine package
Reference an external dll (namespace: External)
Reference a dll which is part of the same solution (namespace: Same)
Create a new Razor View
Try: #using External -> not working
Try: #using Same -> working
I hope someone can help me even if It is not a real problem since razor is able to render the view but it's annoying :(
OK, I finally found a solution. The following answer led me to it:
https://stackoverflow.com/a/19653760/1761291
I tried it and it worked but instead of doing this its ok to only copy the external dll into the bin folder.