diy*_*da_ 1 c# asp.net asp.net-mvc-3
我将模型从一个控制器方法传递到另一个控制器方法,以收集模型字段的所有值.我正在做如下所示
[HttpPost]
public ActionResult A(Model m, string s)
{
if (ModelState.IsValid)
{
if (m.l == null || m.k == null)
{
//Do something.
}
else
return View("B", m); // this is where by debug point comes...
}
return View(m);
}
public ActionResult B(Model m)
{
return View(m);
}
[HttpPost]
public ActionResult B(Model m, string s)
{
if (ModelState.IsValid)
{
if (m.p == null || m.j == null)
{
//do something
}
else
{
// do something and redirect to somewhere else
}
}
Run Code Online (Sandbox Code Playgroud)
但正如我所示,调试点如下所示.
return View("B", m);
Run Code Online (Sandbox Code Playgroud)
这应该是控制器方法"B"但问题是它没有击中控制器方法"B".但它显示了Controller方法"B"的视图所以,我对此问题感到困惑.而且我在方法"B"的httppost中看不到(l,k)的值.这是什么原因.
我想知道,我这样做是对还是错.如果我这样做错了,请你解释一下.擅长MVC的人能帮助我.提前致谢.
该代码 - return View("B", m)
实际上不会重定向到动作 B,它只是使用给定的模型呈现视图 B. 如果要执行操作,则应使用:
return B(m);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3428 次 |
最近记录: |