I am passing an model from one controller method to another controller method to collect all the values to model fields. I am doing as shown below
[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
}
}
But as I have shown the debug point comes here as shown below.
return View("B", m);
This should hit the Controller method “B” But the problem is It does not hit the controller method “B”. But it shows the view for the Controller method “B” So, I am confused about this problem. And I can not see the values for (l,k) in the httppost of method “B”. What is the reason for this.
I want to know that, I am doing this right or wrong. If I am doing this wrong can you please explain on this for a bit. Can someone who is good at MVC help me.
Thanks in advance.
That code —
return View("B", m)— actually doesn’t redirect to the action B, it just renders the view B with the given model. If you want to execute the action, then you should use: