私が提出したとき、私はそれが普通です私の更新アクションメソッド
に当たったとき、あなたはあなたのサーバーにこのIDを送信しない0を得ることはありません。
@using (Html.BeginForm(
"Update", // actionName
"CustomerServiceMessage", // controllerName
FormMethod.Post, // method
new { id = 0 } // htmlAttributes
))
{
...
}
、あなたは次のマークアップ(デフォルトルートを想定)になってしまった:あなたはちょうどHtml.BeginForm
ヘルパーのwrong overloadを使用
<form id="0" method="post" action="/CustomerServiceMessage/Update">
...
</form>
は、問題を参照してください?ここ
とcorrect overloadです:(デフォルトルートを想定して)生成
@using (Html.BeginForm(
"Update", // actionName
"CustomerServiceMessage", // controllerName
new { id = 0 }, // routeValues
FormMethod.Post, // method
new { @class = "foo" } // htmlAttributes
))
{
...
}
:
<form method="post" action="/CustomerServiceMessage/Update/0">
...
</form>
を今、あなたはあなたのid=0
内部に対応するコントローラのアクションを取得します。あなたのコードをより読みやすくするとC# 4.0 named parametersを使用してミスのこの種のを避けることができところで
:
@using (Html.BeginForm(
actionName: "Update",
controllerName: "CustomerServiceMessage",
routeValues: new { id = 0 },
method: FormMethod.Post,
htmlAttributes: new { @class = "foo" }
))
{
...
}
おかげで非常に多く、あなたは正しかったです。今では、もともと私は新しい{id = 0、class = "someClass"}を持っていたとは言及していませんでしたが、上記のあなたの返信ごとにこれを移動した後、今は0を取得して動作しますが、フォーマット)。 – PositiveGuy
@CoffeeAddictを使用して、[正しいオーバーロード](http://msdn.microsoft.com/en-us/library/dd460542.aspx)を使用してください。 '@using(Html.BeginForm(" Update "、" CustomerServiceMessage "新しい{id = 0}、FormMethod.Post、新しい{@class = "foo"})){...} '。ドキュメントを読んだことはありませんか?または、呼び出しているメソッドのパラメータを示すVisual StudioのIntellisenseを参照してください。 –
は本当にあなたの助けを今日ありがとう、ここに良いもの!多くを学んだ。 – PositiveGuy