CrudMonkey
CrudMonkey

Reputation: 55

Servicestack Razor 'Model' does not exist in this context

So, I've tried to figure this out to no avail.

I created a new empty ASP.NET Web Application in VS 2013.

Added ServiceStack framwork and Razor engine vie NuGet.

Added a simple /Services/LogonSvc.cs Service, together with a Logons DTO class with [Route("/Logon")].

Added a simple /Views/Logon/Logons.cshtml

The web.config file should be correct as created by the NuGet templates, right?

But VS is still saying "The name 'model' does not exist in the current context.". The same for "Layout".

Copied the web.config file into the Views folder. No change.

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"     />
            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <system.web>
        <compilation debug="true" targetFramework="4.5">
            <assemblies>
                <add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            </assemblies>
            <buildProviders>
                <add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor" />
            </buildProviders>
        </compilation>
        <httpRuntime targetFramework="4.5" />
        <httpHandlers>
            <add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" />
        </httpHandlers>
    </system.web>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
            <add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
        </handlers>
    </system.webServer>
    <appSettings>
        <add key="webPages:Enabled" value="false" />
    </appSettings>
    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="ServiceStack.Razor.ViewPage">
            <namespaces>
                <add namespace="ServiceStack" />
                <add namespace="ServiceStack.Html" />
                <add namespace="ServiceStack.Razor" />
                <add namespace="ServiceStack.Text" />
                <add namespace="ServiceStack.OrmLite" />
                <add namespace="Telestion.Web" />
                <add namespace="Telestion.Web.Dto"/>
            </namespaces>
        </pages>
    </system.web.webPages.razor>
</configuration>

Logons.cshtml, with squiggly lines under "model" and "Layout":

@model Telestion.Web.Dto.LogonResponse
@{
    Layout = null;
}

<!DOCTYPE html> 
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
</head>
<body>
    <div>    
    </div>
</body>
</html>

Any ideas?

Upvotes: 0

Views: 288

Answers (1)

ristaloff
ristaloff

Reputation: 130

I'm not sure, but this might solve your problem.

In your .cshtml, remove this line:
@model Telestion.Web.Dto.LogonResponse
Then add this at the beginning of the file:
@inherits ServiceStack.Razor.ViewPage<Telestion.Web.Dto.LogonResponse>

Upvotes: 4

Related Questions