私はそれがルートパラメータとしてURLから来ると思います。
たとえば次のようなコントローラがあります。
public class HomeController: Controller
{
public ActionResult Index(int id)
{
vqr model = GetModel(id);
return View(model);
}
[HttpPost]
public ActionResult Index(MyViewModel model)
{
// the model.Id property will be automatically populated here
// because the request was POST /home/index/123
...
}
}
と次のビューを:
@model MyViewModel
@using (Html.BeginForm())
{
<button type="submit">OK</button>
}
今、あなたは/home/index/123
をGETするためにナビゲートし、次のマークアップを取得:
<form action="/home/index/123" method="post">
<button type="submit">OK</button>
</form>
を
フォームのaction
属性に注目してください。それがIDの出所です。基本的にHtml.BeginForm()
ヘルパーは、アクション属性を生成するときに現在のURLを使用します。現在のURLは/home/index/123
です。これは使用されるURLです。
Global.asaxに既定のルートを残しておくと、URLの末尾に{id}
ルートトークンが使用されるため、既定のモデルバインダーでは、ビューモデルのId
プロパティにバインドされます。
ありがとうございました。私はそれがルートパラメータから来ていたと推測していたが、その方法は不明であった。 – NVM