使用  在Visual Studio 10 ASP.NET MVC3中

Bab*_*mes 5 whitespace visual-studio-2010 asp.net-mvc-3

我正在使用Visual Studio 2010 Professional版在ASP.NET MVC3框架中开发应用程序.

我遇到过一种情况,我需要有一个文字空格字符,通常是通过 在HTML中添加(类似的东西)来实现的.

但是,程序会产生运行时错误.

我该如何克服这个问题?

码:

<div class="week">
    @for (int i = 0; i < 7; i++)
    {
        <div class="day">
            @weekStartDay.ToString().Substring(0, 3)
        </div>            
&nbsp;
       weekStartDay = (DayOfWeek)(((int)weekStartDay + 1) % 7);
    }
</div>
Run Code Online (Sandbox Code Playgroud)

错误:

c:***\Documents\Visual Studio 2010\Projects\MvcApplication2\MvcApplication2\Views\Home\Calendar.cshtml(22):错误CS0201:只能使用赋值,调用,递增,递减和新对象表达式作为声明

hea*_*150 21

将您的代码更改为

<div class="week">
    @for (int i = 0; i < 7; i++)
    {
        <div class="day">
            @weekStartDay.ToString().Substring(0, 3)
        </div>            
       @:&nbsp;
       weekStartDay = (DayOfWeek)(((int)weekStartDay + 1) % 7);
    }
</div>
Run Code Online (Sandbox Code Playgroud)

@:告诉Razor视图引擎&nbsp;是纯文本