0
我正在開發使用C#和SQL Server 2005檢索值,並將其保存在列表中的ASP MVC 3
我用的也是實體框架和準則第一種方法的ASP淨MVC 3應用程序。
我想保存在我的視圖(在窗體中)選擇或進入本地變量的值。
所以我在我的視圖模型創建名單:
public List<Gamme> ListG = new List<Gamme>();
我現在想要從視圖值,並把這個清單當然的客體:
public Gamme A = new Gamme (........);
這是視圖其中值entred:
<% 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>
UPDATE: 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);
}
thx ,,但它如何從表單中檢索數據? – anouar
@anouar在你的視圖中,你必須有一個表單將發送到您的控制器 –
所以我會使用BeginForm?和UserGammes在控制器中是未知的? – anouar