2012-08-17 40 views
1

我是一名ASP.NET MVC 3 noob学习工作通过wrox book我的方式 - 但将代码翻译为VB,因为我在一家VB商店工作。如何在html助手生成的表单中使用html(使用razor语法)?

我想这个C#代码转换成VB产生一个观点:

@using (Html.BeginForm(“Search”, “Home”, FormMethod.Get)) { 
    <input type=”text” name=”q” /> 
    <input type=”submit” value=”Search” /> 
} 

好像刚刚更换支架的一个相当简单的例子,但我从编译器遇到下面的错误,并能不知道为什么。

@Using (Html.BeginForm("Search", "Home", FormMethod.Get)) 
     <input type="text" name="q" />   // '>' expected. 
     <input type="submit" value="Search"/>  // '>' expected. 
End Using 

我敢肯定这是一个简单的sytnax问题,但我不知道语法。我也试图理解HTML助手和剃须刀,所以有很多新的东西。有人可以解释!

回答

1

您需要标记内的代码块的HTML标记的像内Using@开始或与<text>

@是单行:

@Using (Html.BeginForm("Search", "Home", FormMethod.Get)) 
     @<input type="text" name="q" /> 
     @<input type="submit" value="Search"/> 
End Using 

<text>是多行:

@Using (Html.BeginForm("Search", "Home", FormMethod.Get)) 
     @<text> 
      <input type="text" name="q" />   
      <input type="submit" value="Search"/>  
     </text> 
End Using 

欲了解更多信息,请参阅:Combining text, markup, and code in code blocks

+0

感谢解释 – bernie2436 2012-08-17 16:57:17

+0

也许你应该添加不同对你的问题有更多的描述性标题:比如如何在vb.net razor视图中使用Html.BeginForm中的html或类似的东西那 – nemesv 2012-08-17 16:59:01