gpt4 book ai didi

c# - 语法错误,Razor 中预期为 '>'

转载 作者:行者123 更新时间:2023-11-30 16:50:41 26 4
gpt4 key购买 nike

好的,所以我一直在尝试使用元组将多个模型传递给 View ,到目前为止,它的效果非常好。当我尝试这个时问题来了

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

如果我要输入类似的内容:

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

或者

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

和相应的服务器端代码,它完美地工作。

在此先感谢任何可以帮助我的人;我要放弃这个问题了。

最佳答案

由于您基本上是在 View 中传递多个模型,而 MVC 旨在将一种类型传递到一个 View ,因此我强烈建议您创建一个包含所有实体的单一模型:

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; }
}

然后您可以将其设置为 View 中的模型:

@model ViewModel

关于c# - 语法错误,Razor 中预期为 '>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34681366/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com