Asp.net mvc 将字符串传递给匿名对象以标记帮助器

Asp.net mvc 将字符串传递给匿名对象以标记帮助器,asp.net-mvc,asp.net-core-mvc,tag-helpers,asp.net-core-tag-helpers,Asp.net Mvc,Asp.net Core Mvc,Tag Helpers,Asp.net Core Tag Helpers,my tag helper的用法: <website-information info="new WebInfo { Age = 55, Author = "Test" }"></website-information> 我遇到了编译错误您不能仅仅插入一个复杂的对象。根据您希望输出在客户端的确切外观,我们假设: <website-information info="Age:55,Author:Test"></website-information>

my tag helper的用法:

<website-information info="new WebInfo { Age = 55, Author = "Test" }"></website-information>

我遇到了编译错误

您不能仅仅插入一个复杂的对象。根据您希望输出在客户端的确切外观,我们假设:

<website-information info="Age:55,Author:Test"></website-information>

然后你会这样做:

<website-information info="@("Age:55,Author:Test")"></website-information>

或:

@{
var webInfo=newwebinfo{Age=55,Author=“Test”};
}

Razor允许我们使用
@
计算C#表达式。因此,您可以使用
@
获取复杂对象

对于您的场景,您可以简单地使用以下代码:


<website-information info="@("Age:55,Author:Test")"></website-information>
@{
   var webInfo = new WebInfo { Age = 55, Author = "Test" };

   <website-information info="@("Age:" + webInfo.Age + ",Author:" + webInfo.Author)"></website-information>

}