StumpyXXL
StumpyXXL

Reputation: 43

How to fix "System.Guid is a type but used like a variable" when using "@Guid"?

So I have no idea why I'm getting this issue with the Guid here. Can anyone please lend some insight?

@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) 

Upvotes: 0

Views: 467

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 156978

You should put initialization in a code block. Then you can drop all the @s:

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

The Introduction to ASP.NET Web Programming Using the Razor Syntax (C#) is a must read.

Upvotes: 2

Related Questions