我正在使用 C# 和 SQL Server 2005 开发一个 ASP .Net MVC 3 应用程序。
我也在使用实体框架和代码优先方法。
我想从视图“Gestion.ascx”中检索值并使用按钮将它们保存在列表中。
这是我尝试但没有任何结果:
The View Gestion :
<% 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>
控制器“AnouarController”是填充视图“Gestion”的控制器:
public class AnouarController : Controller
{
private GammeContext db = new GammeContext();
//
// GET: /Anouar/
public ActionResult Gestion(FlowViewModel model)
{
model.YourGammeModel = new Gamme();
return PartialView(model);
}
public ActionResult Save(Gamme gamme)
{
UserGammes.Add("currentUserID", gamme);
}
}
最后是模型 FlowViewModel :
public class FlowViewModel
{
[Key]
public string IDv { get; set; }
[NotMapped]
public SelectList PostesItems { get; set; }
public List<Profile_Ga> Profile_GaItems { get; set; }
public List<Gamme> GaItems { get; set; }
public Gamme YourGammeModel { get; set; }
public int SelectedProfile_Ga { get; set; }
public int SelectedGamme{ get; set; }
public int SelectedPoste { get; set; }
public int PostePrecedentSelected { get; set; }
public int PosteSuivantSelected { get; set; }
private static Dictionary<string, Gamme> userGammes;
public static Dictionary<string, Gamme> UserGammes
{
get
{
if (userGammes == null)
{
userGammes = new Dictionary<string, Gamme>();
}
return userGammes;
}
}
}