using
ステートメントを剃刀ビューで一般的なメソッドで使用できるようにする方法はありますか?たとえば、私は、HTMLタグとしてかみそり解釈<Controller>
いるので、Webフォームは 剃刀ビューで汎用メソッドを使用する
<% using(Html.BeginForm<Controller>(c => c.Method()))
{ %>
Some code
<% } %>
この
@using(Html.BeginForm<Controller>(c => c.Method()))
{
Some code
}
ようにかみそりに変換スニペットが、それは動作しませんしたいと思います。かっこを追加すると、かみそりにはBeginForm
を開始および終了する中括弧が含まれないため、どちらも機能しません。私が試したさまざまなアプローチは以下の通りです。それ以上考えることはできません。
@using(Html.BeginForm<Controller>(c => c.Method())) // Interpreted as c# to '<Controller>'
{ // interpreted as HTML
Some code // interpreted as HTML
} // interpreted as HTML
@(using(Html.BeginForm<Controller>(c => c.Method()))) // Interpreted as c#
{ // interpreted as HTML
Some code // interpreted as HTML
} // interpreted as HTML
@{using(Html.BeginForm<Controller>(c => c.Method())) // Interpreted as c#
{ // interpreted as c#
Some code // interpreted as c#
} // interpreted as c#
} // interpreted as c#
@(using(Html.BeginForm<Controller>(c => c.Method()))) // Interpreted as c#
@{ // interpreted as c#
Some code // interpreted as c#
} // interpreted as c#
aynoneはこれを行う方法を知っていますか?
更新:これを行う方法は上記の3番目の方法のようです。かみそりは明らかに次のように機能します:
@{using(Html.BeginForm<Controller>(c => c.Method())) // Interpreted as c#
{ // interpreted as c#
<p> // interpreted as HTML
Some text // interpreted as HTML
@Code // interpreted as c#
</p> // interpreted as HTML
} // interpreted as c#
} // interpreted as c#
最も明白なやり方はありませんが、機能します。
更新2:上記のオプション#1が期待どおりに機能するため、Razorはおそらくいつでも更新されています。
@(using(Html.BeginForm<Controller>(c => c.Method())))
またはコードブロックを使用:あなたは括弧で文全体をラップする場合、どのよう
@using(Html.BeginForm<Controller>(c => c.Method()))
{
Some code
}
私の最後にはうまくいくようです。しかし、 'BeginForm'は利用できません(私は簡単なヘルパーメソッドをテストしました)ので、外部のライブラリなどを使用していますか? Razor Syntaxのエラーは何ですか? –
Buildstarted
Microsoft.Web.Mvc.dllのMvcContrib拡張を使用しています。これには、強く型付けされた多数のHTMLヘルパーが含まれています。エラーは、@(Html.BeginForm(...))は正常に動作しますが、@using(Html.BeginForm (...))はそうではなく、フォーマットする方法を理解できません作業。 –