views:

49

answers:

2

Hi there,

Will keep this as simple a possible:-

I have a have a controller which will return either ViewA or ViewB - e.g.

[HttpPost]
public ActionResult ViewA(BlahModel model)
{
    if (isTrue)
      return View(model);
    else
      return View("ViewB", model);
}

...

The problem I have is that ViewB has a form on it. And what happens is that if it gets returned, the action attribute of the tag still points to ViewA.

/MyControllerName/ViewA

I thought I could do something like this:

using (Html.BeginForm("ViewB","MyControllerName"))

But this returns the following URL in the markup:

/ViewB?action=ViewB&controller=MyControllerName

How can I get the HTML Helper to correctly return the following?

/MyControllerName/ViewB

Many thanks

UPDATE

This was indeed caused by some ugly legacy routing from when the project was half-way between WebForms and MVC

+2  A: 

It's issue in routing table. Routing engine can't find route statisfies this action\controller and simply put theese parameters to querystring.

gandjustas
+2  A: 

Do you have an action named ViewB? If not, the routing engine can't understand what you're asking for and appends extra variables to the querystring for the target. One action that renders two different views is fine, but if you want ViewB to POST somewhere different than ViewA, then you need an action in your controller for ViewB.

EDIT: Further clarification, if the ViewA action should always be called, then you don't need a ViewB action, and your ViewB view should just post back to the ViewA action.

If the ViewB view needs to execute a different action than your ViewA view, then you need to create another action for ViewB to POST to.

Sorry for all the bold, but I just wanted to be clear about the differences between actions and views.

Scott Anderson