C# と SQL Server 2005 を使用して ASP .Net MVC 3 アプリケーションを開発しています。
Entity Framework と Code First Method も使用しています。
ビュー (フォーム内) で選択または入力した値をローカル変数に保存したいと考えています。
だから私は自分のビューモデルにリストを作成します:
public List<Gamme> ListG = new List<Gamme>();
ビューから値を取得し、このリストのオブジェクトに入れたい:
public Gamme A = new Gamme (........);
これは、値が入力されるビューです。
<% using (Html.BeginForm("Save", "Anouar")) { %>
<%: Html.ValidationSummary(true) %>
<fieldset class="parametrage">
<legend>Gestion de Gamme</legend>
<div><%:Html.Label("Poste :")%><%: Html.DropDownList("SelectedPoste", Model.PostesItems)%><input type="checkbox" name="option1" value="Poste Initial" id= "chkMain" onclick="test();"/>Poste Initial<input type="checkbox" name="option2" value="Poste Final" id= "chkFirst" onclick="test2();"/>Poste Final</div>
<div><%:Html.Label("Nombre de Passage :")%><%: Html.EditorFor(x=>x.YourGammeModel.Nbr_Passage)%></div>
<div><%:Html.Label("Position :")%><%: Html.EditorFor(x=>x.YourGammeModel.Position)%></div>
<div><%:Html.Label("Poste Précédent :")%><%: Html.DropDownList("PostePrecedentSelected", Model.PostesItems)%></div>
<div><%:Html.Label("Poste Suivant :")%><%: Html.DropDownList("PosteSuivantSelected", Model.PostesItems)%></div>
<div><input type="submit" value="Enregistrer" id="btnSave" /></div>
</fieldset>
更新: FlowViewModel:
private static Dictionary<string, Gamme> userGammes;
public static Dictionary<string, Gamme> UserGammes
{
get
{
if (userGammes == null)
{
userGammes = new Dictionary<string, Gamme>();
}
return userGammes;
}
}
およびビューのコントローラー:
public ActionResult Save(Gamme gamme)
{
UserGammes.Add("currentUserID", gamme);
}