C# 在ASP MVC 3中,从一个视图传递到另一个视图的值为NULL
我正在使用C#和SQLServer2005开发一个ASP.NETMVC3应用程序 我还使用实体框架和代码优先方法 在视图C# 在ASP MVC 3中,从一个视图传递到另一个视图的值为NULL,c#,visual-studio-2010,asp.net-mvc-3,C#,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");
}
注意:
我没有在应用程序中忘记这一点:
<% using (Html.BeginForm("app", "ProfileGa")) { %>
ProfileGa
是我的控制器的名称。首先,您的下拉列表位于索引视图中,选择正在那里进行。然后您将重定向到ProfileGa/Application
,并将此信息留在后面
我将更改此按钮:
<input type="button" value="Appliquer" .. etc
并添加Post
版本的应用程序
[HttpPost]
public ActionResult Application(FlowViewModel model)
{
// Do whatever
return View(model);
}
然后,当您进入应用程序
视图时,它应该仍然具有与它在索引
中留下的信息相同的信息
要检查这是否有效,请在返回视图(模型)处放置断点
并查看模型的内容
但是,从视图中发布null
可能意味着您的
语句中存在错误,因此,如果上述操作没有任何作用,请从“应用程序”视图中发布代码。thx获取答案,我像这样更改按钮:
我像这样包装我的下拉列表:model.SelectedProfile\u Ga,new SelectList(model.Profile\u GaItems,“ID\u game”,“ID\u game”),new{@ID=“gg”})%>
我也像上面提到的那样更改操作,但当我执行时,按钮变成静态,当我单击“否”时,什么也不做,我的意思是不打一针。using
指令告诉它去哪里。是的,我也尝试了,没有onclick,结果相同,我对dropdownlist做的是这样的吗
using (Html.BeginForm("Application", "ProfileGa")) {
[HttpPost]
public ActionResult Application(FlowViewModel model)
{
// Do whatever
return View(model);
}