2013-05-07 34 views
8

我不确定为什么这个语法会出现错误“输入未声明,可能因防护级别而无法访问”,必须将“@html(”错误。在Razor中使用VB.net MVC不能正常工作

此块抱怨错误

@Using (Html.BeginForm("GetUser", "UserProfile", FormMethod.Post)) 
     Enter User id :- @Html.TextBox("UserId",Model) -- This line must write in this way @Html("Enter User id :-") 
     <input type="submit" value="Submit data" /> --This line complain ">" expected" 
    End Using 

如果重写这样的代码中,抱怨消失了,但在像下面

图像开头的输出显示“System.Web.MVC.Html”
 @Html.BeginForm("GetUser", "UserProfile", FormMethod.Post) 
     Enter User id :- @Html.TextBox("UserId",Model) 

    <input type="submit" value="Submit data" /> 

enter image description here

喜nemesv如果使用@<Text>
,它的抱怨这一点 - “使用必须结束而终止使用”> enter image description here

+0

你已经忘记关闭@'在我的例子中看到我有:'@'注意关闭''该线。 – nemesv 2013-05-08 07:28:59

+0

反对!在MVC中太新了。一切似乎都对我来说很新鲜,谢谢! – tsohtan 2013-05-08 07:30:27

+0

[为什么@Using Html.BeginForm中的普通标记需要@?](http://stackoverflow.com/questions/10225394/why-does-normal-markup-inside-an-using-html- beginform-need-an) – KyleMit 2014-11-10 21:58:23

回答

8

当你是一个Using块里面你是在剃刀“代码模式” 。

因此,您需要使用@:(对于单行语句)或@<text> .. </text>(对于多行语句)切换回“文本模式”并输出html。

随着使用@:

@Using (Html.BeginForm("GetUser", "UserProfile", FormMethod.Post)) 
     @:Enter User id :- @Html.TextBox("UserId",Model) 
     @:<input type="submit" value="Submit data" /> 
End Using 

或使用@<text>

@Using (Html.BeginForm("GetUser", "UserProfile", FormMethod.Post)) 
     @<text>Enter User id :-</text> @Html.TextBox("UserId",Model) 
     @<text><input type="submit" value="Submit data" /></text> 
End Using 

参见进一步信息的Combining text, markup, and code in code blocks部分。

+0

“@”在“”前面是一个VB事物吗?我知道它并不需要它C# – mattytommo 2013-05-07 08:45:25

+1

@mattytommo是'@'是C#中的VB唯一的东西,你只需要'' – nemesv 2013-05-07 08:53:09

+0

我仍然有这个错误:'>'在浏览器中运行时预期。在这一行@:但是在设计时没关系,并且@不适合我。我正在使用vs 2012. .net 4.5 – tsohtan 2013-05-08 07:07:57