J2ghz
J2ghz

Reputation: 659

VB.NET Razor syntax

Why does this work?

<h2>Index</h2>
@Html.ActionLink("Create New", "Create")
@Using (Html.BeginForm())
    @<p>
        Title: @Html.TextBox("SearchString") <br />
        <input type="submit" value="Filter" />
    </p>
End Using

but this does not?

<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
@Using (Html.BeginForm())
    @<p>
        Title: @Html.TextBox("SearchString") <br />
        <input type="submit" value="Filter" />
    </p>
End Using
</p>

when saving this, VS changes it to

...
@Using (Html.BeginForm())
@
<p>
...

which throws lots of erros about html not being code

Edit: whole file, don't know if relevant http://pastebin.com/dJj5xiBC

Edit2: I'm trying to copy a C# code from this tutorial http://www.asp.net/mvc/overview/getting-started/introduction/adding-search

<p> 
    @Html.ActionLink("Create New", "Create") 

     @using (Html.BeginForm()){    
         <p> Title: @Html.TextBox("SearchString") <br />   
         <input type="submit" value="Filter" /></p> 
        } 
</p>

Upvotes: 1

Views: 346

Answers (1)

Nadir Mezhoudi
Nadir Mezhoudi

Reputation: 155

You c'ant use paragraph tag as container of form try to replac it by div as follows:

 <h2>Index</h2>
<div>
    @Html.ActionLink("Create New", "Create")
    @Using (Html.BeginForm())

        @<p>
            Title: @Html.TextBox("SearchString") <br />
            <input type="submit" value="Filter" />
        </p>

    End Using
</div> 

Upvotes: 1

Related Questions