developer23084719
developer23084719

Reputation: 11

Migrating .net framework to .netcore 3.1 (Servicestack.Razor Views)

I'm migrating a .net framework web to .netcore

Having issues with moving the 'Views' folder. It seems that every razor page with @inherits ViewPage<TModel>

I get an error "The type or namespace 'ViewPage<>' could not be found (are you missing a using directive or an assembly reference?).

I've installed ServiceStack.Razor and ServiceStack.Mvc nuget package in my project but it's not able to recognize it in Views folder.

On my _ViewImports.cshtml, I have also added @using package references

Also, I am using 'Request.[]' from ServiceStack.Razor but it's unable to recognize Request.

Any ideas of what I'm missing? Should I be updating it to @model instead? When I update to @model it's working fine but 'Request' is still unrecognized

Upvotes: 1

Views: 190

Answers (1)

mythz
mythz

Reputation: 143399

Unlike most features in ServiceStack which could be ported and multi-targeted to support both .NET Framework and .NET Core, ServiceStack.Razor's coupling to System.Web could not support .NET Core.

Instead ServiceStack.Razor for .NET Core was rewritten to work on top of ASP.NET Core MVC which is only contained in the ServiceStack.Mvc package not the the .NET Framework only ServiceStack.Razor package (which shouldn't be referenced in .NET Core).

Most of the syntax remained the same so porting should still require a small amount of effort as seen in ServiceStack.Razor's Razor Rockstars .NET Core port vs the original .NET Framework:

But given that it's a rewrite that works on top of ASP.NET Core MVC I wouldn't try to convert your existing ServiceStack.Razor project but instead to start with an empty new razor project so it starts from a well-known working configuration and then copying your existing Razor Views and Services across to the new project.

You can create a razor project via either the command-line:

$ x new razor ProjectName

Or using ServiceStack's online project template creator at: https://servicestack.net/start

Upvotes: 0

Related Questions