C# 如何在ASP MVC 3中从一个视图向另一个视图发送值
我正在使用C#和SQLServer2005开发一个ASP.NETMVC3应用程序 我还使用实体框架和代码优先方法 在视图C# 如何在ASP MVC 3中从一个视图向另一个视图发送值,c#,sql-server,visual-studio-2010,asp.net-mvc-3,C#,Sql Server,Visual Studio 2010,Asp.net Mvc 3,我正在使用C#和SQLServer2005开发一个ASP.NETMVC3应用程序 我还使用实体框架和代码优先方法 在视图索引中,我有一个DropDownListGamme。我在视图中定义其所选项目,如下所示: public string SelectedProfile_Ga { get; set; } 在这个视图中,我有一个按钮贴花器,它将我带到另一个视图应用程序 <input type="button" value="Appliquer" id="appliquer" onclick=
索引中,我有一个DropDownListGamme
。我在视图中定义其所选项目,如下所示:
public string SelectedProfile_Ga { get; set; }
在这个视图中,我有一个按钮贴花器
,它将我带到另一个视图应用程序
<input type="button" value="Appliquer" id="appliquer" onclick="window.location = 'ProfileGa/Application'"/>
当我点击appriquer
时,我想将我的下拉列表Gamme
中选择的值保存在我的基础中
问题是,当我更改视图(退出页面索引并打开应用程序)时,此值被传递到NULL
我通过调试发现了这一点
控制器操作:
[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");
}
编辑:
我认为:
<%: Html.ActionLink("Appliquer", "Application", new { id=Model.SelectedProfile_Ga }) %>
在视图应用程序中:
<% using (Html.BeginForm("appl", "ProfileGa")) { %>
<input type="submit" value="Appliquer" id="appl" />
<%}%>
您是否尝试过使用参数?我看到了,,,但我的问题是,我没有一个按钮的操作方法可以将我带到另一个视图,,,,我有:
,但在这种情况下,您只是将新的url设置到网站,而不是将其发回(带有数据)。这是您的问题。啊,好的!那么我可以放一个ActionLink吗??问题是我想要一个按钮没有链接,,,有没有办法用按钮发布数据?当然,你必须添加另一个表单并将按钮提交给控制器。
[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;
}
<% using (Html.BeginForm("appl", "ProfileGa")) { %>
<input type="submit" value="Appliquer" id="appl" />
<%}%>