I am developing an ASP .Net MVC 3 application using C# and SQL Server 2005.
I am using also Entity Framework and Code First Method.
In a view Index
, I have a DropDownList Gamme
. I define its item selected in my view, like this :
public string SelectedProfile_Ga { get; set; }
In this view, I have a button Appliquer
that took me to another view Application
.
<input type="button" value="Appliquer" id="appliquer" onclick="window.location = 'ProfileGa/Application'"/>
In the view Application
, I have a button submit Appliquer
.
<input type="submit" value="Appliquer" id="appl" />
When I click on Appliquer
, I want save the value selected in my DropDownList Gamme
in my base.
The problem is that this value is passed NULL
when i change the view (exit page Index and open Application).
I find that with Debugging.
The Controller action :
[HttpPost]
public ActionResult app(FlowViewModel model)
{
Famille fam = new Famille();
fam.ID_Gamme = model.SelectedProfile_Ga;
db.Familles.Add(fam);
db.SaveChanges();
return RedirectToAction("Application");
}
EDIT : In my view :
<%: Html.ActionLink("Appliquer", "Application", new { id=Model.SelectedProfile_Ga }) %>
In the action method (controller ProfileGa):
[HttpPost]
public ActionResult appl(string id)
{
FlowViewModel model = new FlowViewModel();
Famille fam = new Famille();
Profile_Ga profile_ga = db.Profil_Gas.Find(id);
fam = db.Familles.Find(model.SelectedFamille);
fam.ID_Gamme = model.SelectedProfile_Ga;
}
In the View application :
<% using (Html.BeginForm("appl", "ProfileGa")) { %>
<input type="submit" value="Appliquer" id="appl" />
<%}%>