如何修复" System.Guid是一种类型,但用作变量"使用" @ Guid"?

时间:2015-05-01 13:26:54

标签: c# asp.net-mvc razor guid

所以我不知道为什么我会在这里与Guid讨论这个问题。任何人都可以提供一些见解吗?

@using System;
@using AC.Common.Comparing
@using AC.Business.Object.B2BOrderHandling
@using AC.Website.Areas.OrderManagement.Views.B2BOrderHandling.App_LocalResources
@using AC.Website.Areas.OrderManagement.Models

@model ComparisonRowModel

@Guid messageID = System.Guid.NewGuid();
@string x = messageID.ToString();

<div @(Model.Current != null ? string.Format("orderdetailsid={0}", Model.Current.OrderDetailsID) : "") data-guid="@(x)" class="current menuitem @(Model.ChangeType == B2BMenuItemChangeTypeModel.Deleted ? "deleted" : "")">
@switch (Model.ChangeType) 

1 个答案:

答案 0 :(得分:2)

您应该在代码块中放置初始化。然后你可以删除所有@ s:

@{
    Guid messageID = System.Guid.NewGuid();
    string x = messageID.ToString();
}

必须阅读Introduction to ASP.NET Web Programming Using the Razor Syntax (C#)