Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error, '>' expected in Razor

Ok, so I've been trying to pass multiple models to a View using a Tuple and it's worked like a charm so far. Problem comes when I try this

@model Tuple<Smart_WEB.Models.Room, List<IGrouping<string, Smart_WEB.Models.Song>>, List<IGrouping<string, Smart_WEB.Models.Video>>>

The 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 29:
Line 30:
Line 31: public class _Page_Views_Home_Index_cshtml : System.Web.Mvc.WebViewPage<Tuple<Smart_WEB.Models.Room { Line 32:
Line 33: #line hidden

And if I were to put something like:

@model Tuple<Smart_WEB.Models.Room, List<IGrouping<string, Smart_WEB.Models.Video>>>

Or

@model Tuple<Smart_WEB.Models.Room, List<IGrouping<string, Smart_WEB.Models.Song>>>

and the respective server side code it works perfectly.

Thanks in advance to anyone who can help me; I'm about to give up on this problem.

like image 952
Jairo Avatar asked Sep 08 '26 09:09

Jairo


1 Answers

As you are basically passing multiple models in your view and MVC is designed to pass one type to one view, I strongly advise you to create a single model that wraps all your entities:

public class ViewModel
{
    public Smart_WEB.Models.Room Room { get; set; }
    public List<IGrouping<string, Smart_WEB.Models.Song>> Songs { get; set; }
    List<IGrouping<string, Smart_WEB.Models.Video>> Videos { get; set; }
}

Then you can set it as model in your view:

@model ViewModel
like image 97
user449689 Avatar answered Sep 10 '26 21:09

user449689



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!