首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

RAZOR中的CSHTML怎么调用方法呢

2012-10-19 
RAZOR中的CSHTML如何调用方法呢?using Systemusing System.Collections.Genericusing System.Linqusing

RAZOR中的CSHTML如何调用方法呢?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;namespace MyGame
{
  public class AppGlobalInfo
  {
  public static string ThemeName()
  {
  return "Default";
  }
  }
}

@{
  Layout = "~/Views/Themes/MyGame/My/_Administrator.cshtml";
  ViewBag.Title = "???";
}
@for (int i = 0; i < 100; i++)
{
  @AppGlobalInfo.AppGlobalInfo.ThemeName();
  <p style="font-size:10px;">@i</p> 
}


Server Error in '/' Application.Compilation ErrorDescription: 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: CS0433: The type MyGame.AppGlobalInfo' exists in both 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\74643291\eb640423\assembly\dl3\ff8dc3e8\002f0e16_0f51cd01\MyGame.dll' and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\74643291\eb640423\App_Code.a9cl9ms2.dll'

Source Error:







Line 6: @for (int i = 0; i < 100; i++)Line 7: {Line 8: @MyGame.AppGlobalInfo.ThemeName();Line 9: <p style="font-size:10px;">@i</p> Line 10: }


[解决办法]
@AppGlobalInfo.AppGlobalInfo.ThemeName();
是否应是@AppGlobalInfo.ThemeName();

[解决办法]
@Html.Raw(AppGlobalInfo.AppGlobalInfo.ThemeName());

热点排行