あなたは以下のようなモデルを持つことができます
public class MyActionFilters
{
public string Property1{get;set;}
public string Property2{get;set;}
public string[] Property3{get;set;}
// add any number of properties....
}
GetActionメソッドで空のモデルを渡すことができます
ActionResult ActionName()
{
MyActionFilters myEmptyActionFilers= new MyActionFilters();
View(myEmptyActionFilers)
}
フォームで
Html.TextBoxFor(model => model.Property1)
Html.TextBoxFor(model => model.Property2)
次に、postメソッドで、前のコードを削除したフォームに入力されたモデルにアクセスできます。新しいコードは編集タグの後にあります:)
編集:申し訳ありませんが、私は周りにいませんでした。この種の機能は、AJAXを使用して簡単に実現できます:)
以下のようになります。
[HttpPost]
PartialViewResult ActionName(MyActionFilters myActionFilers)// this is magic
{
/*you can access the properties here like myActionFilers.Property1 and pass the
same object after any manipulation. Or if you decided have a model which contains
a variable to hold the search results as well. That is good.*/
return PartialView(myActionFilers);
}
これまでのところ、これは参照するのに良い例です。
jquery.unobtrusive-ajax.js
また、ビューにスクリプト参照を追加することを忘れないでください。そうでない場合、Ajaxは影響しません。与えられた例では、あなたが見ることができるように、彼は_Layoutでそれを行いました。
PS:ビューに渡されるモデルのプロパティを賢く選択してAjaxをお楽しみください!!