Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CS1003: Syntax error, '>' expected in Razor

I'm trying something new (to me) in using an abstract base class for my layout viewmodel.

The problem is that when I run the site as is, it throws a very cryptic (to me) exception. What does this exception mean, and what might I do to resolve it?

Layout

@model MyApp.Core.ViewModels.LayoutViewModel

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@Model.Title</title>
</head>
<body>
    <div>
       @RenderBody()
    </div>
</body>
</html>

Index

@model MyApp.Core.ViewModels.Home.IndexViewModel;

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<h1>@Model.Body</h1>

LayoutViewModel

namespace MyApp.Core.ViewModels
{
    public abstract class LayoutViewModel
    {
        public string Title { get; set; }
    }
}

IndexViewModel

namespace MyApp.Core.ViewModels.Home
{
    public class IndexViewModel : LayoutViewModel
    {
        public string Body { get; set; }
    }
}

Controller

[HttpGet]
public ActionResult Index()
{
    var model = new IndexViewModel
        {
            Title = "Hello World",
            Body = "Hello World"
        };


    return View(model);
}

And the Exception

Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1003: Syntax error, '>' expected

Source Error:

Line 27:
Line 28:
Line 29:     public class _Page_Views_Home_Index_cshtml : 
System.Web.Mvc.WebViewPage<FutureStateMobile.Core.ViewModels.Home.IndexViewModel;>
{ 
Line 30:          
Line 31: #line hidden

Source File: c:\Users\Chase\AppData\Local\Temp\Temporary ASP.NET Files\root\b314e0d7\36f522db\App_Web_index.cshtml.a8d08dba.yr7oemfz.0.cs Line: 29

like image 419
Chase Florell Avatar asked Sep 18 '13 16:09

Chase Florell


2 Answers

Compare and contrast:

Layout

@model MyApp.Core.ViewModels.LayoutViewModel

Index

@model MyApp.Core.ViewModels.Home.IndexViewModel;

Got it yet? Here's the answer:

one of them has a ; which shouldn't be there

like image 182
AakashM Avatar answered Sep 27 '22 21:09

AakashM


I just add the line twice, and deleted... problem solved!

@model MyApp.Core.ViewModels.LayoutViewModel
@model MyApp.Core.ViewModels.Layout_OrOther_Model

Try to compile, you get an error (only one model blah, blah..) Delete one of them.

@model MyApp.Core.ViewModels.LayoutViewModel

Compile.

That works for me!

like image 30
Marcelo Lujan Avatar answered Sep 27 '22 22:09

Marcelo Lujan