只有赋值,调用,递增,递减,等待,新对象表达式才能用作语句 [英] only assignment,call,increment,decrement,await,new object expression can be used as a statement

查看:82
本文介绍了只有赋值,调用,递增,递减,等待,新对象表达式才能用作语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

在我的项目中创建数据访问层之后,我在我的控制器中创建了新方法,并且还创建了一个新视图....现在我只想将所有数据从模型到我的新视图,我在视图中写了这一行:@model otto.Models.Supply;

我得到的错误是:只有赋值,调用,递增,递减,等待,新对象表达可以作为一个声明



我应该怎么做?



提前感谢

解决方案

从视图中的 @model 指令中删除分号:

< pre lang =razor> @ model otto.Models.Supply


怎么办?显然,使用赋值,调用,递增,递减,等待或新作为语句。 :-)



请问,在没有显示导致此消息的代码的情况下告诉我们错误消息有什么用?但更重要的是,为什么在不了解语言基础知识和掌握最基本技能的情况下创建数据访问层之类的东西?基本的东西最好用最简单的样品来学习,而不是真正的项目。



我们面临这样的例外情况。好吧,将你的错误信息逆向工程到你的错误中是没有意义的,但是,在这种情况下,非常有趣。我们怎么能设法写一个非声明并导致这个错误?显然,预计会发表声明。让我们看看:

 静态  void  Foo (){
Foo;此行中 // ,而不是声明
}



或者说,

 静态  class  MyClass {} 
static void Foo(){
MyClass; // 此行;
// 但是,在这种情况下,
// 会有两条错误消息
}

类似的东西。 (添加静态一词只是为了扩展可能出现这些错误信息的可能情境的数量。)



但如果我还要解释什么是在这些代码中错了,我会和一个错误的听众说话。的确,当一个人面临这样的错误?当一个人简单地快速输入代码并且几乎意外地在一行之前点击Build,如果完成,否则这个人不知道她/他在做什么;只有这样才能提出这样的问题。



-SA


hi!
After I created Data Access Layer in my project ,I created new method in my controller and also a new view....now I just want to push all my data from the model to my new view and i wrote this line in the view : @model otto.Models.Supply;
the error that I got is : only assignment,call,increment,decrement,await,new object expression can be used as a statement

what I should do?

thanks in advance

解决方案

Remove the semi-colon from the @model directive in your view:

@model otto.Models.Supply


What to do? Apparently, use assignment, call, increment, decrement, await or new as a statement. :-)

Please, what's the use of telling us an error message without showing some code causing this message? But, more importantly, why creating things like "Data Access Layer" without knowing the basics of language and having most basic skills? Fundamental things are best learned on the simplest samples, not on real projects.

Where we face such exceptions. Well, "reverse-engineering" your error message into your error would be quite pointless, but, in this case, pretty funny. How can we even managed to write a non-statement and cause this error? Apparently, where a statement is expected. Let's see:

static void Foo() {
    Foo; // in this line, not a statement
}


or, say,

static class MyClass { }
static void Foo() {
    MyClass; // this this line;
    // however, in this case,
    // there will be two error messages
}

Something like that. (The word "static" is added only to extend the number of possible contexts where exactly these error messages should be expected.)

But if I also had to explain what's wrong in these pieces of "code", I would be talking to a wrong listener. Indeed, when one face such mistakes? When one simply enters code fast and nearly accidentally clicks "Build" before a line if complete, otherwise this is the person having no clue what she/he is doing; only then such questions may be posed.

—SA


这篇关于只有赋值,调用,递增,递减,等待,新对象表达式才能用作语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆