tags:

views:

33

answers:

1

I have a control on my master page that I create using RenderAction. The problem I'm having is when I use a form somewhere else on the page it renders this action using HttpPost instead of HttpGet.

I get why it's doing this as the request is a post, however this is not the desired or expected result as the control was not in anyway involved in the user action.

Simplified example:

<div id="search-panel">
    <% Html.RenderAction("Index", "TestController"); %>
</div>
<% using (Html.BeginForm("Update", "Products")
{%>
    <%: Html.Hidden("productId", Model.ProductId) %>
    <%: Html.TextBoxFor(model => Model.Name)%>
    <input type="submit" vaue="Submit"/>            
<% }%>

When the user submits the Update Products form the form in Index TestController is also rendered as if it was submitted. This makes the RenderAction for controls somewhat useless.

Any idea's on workarounds or better approaches would be most welcome.

Cheers

UPDATE

I do not wish to use RenderPartial as suggested for the following reason. The control in this case is a search box with many options populated from a database. The logic for this control/view should be in the SearchController.

The main area of the page may contain views form other controllers, e.g. a product view. To use RenderPartial, the ProductController would have to create view data for the search box. This is not it's job, the ProductController has no business knowing the Search functionality even exists.

I have found a solution using this blog post. It also explains the problem I'm having well. It seems odd that MVC is missing this functionality.

+2  A: 

Is there a reason you're using RenderAction instead of RenderPartial? RenderAction uses a POST, RenderPartial uses a GET.

Benjamin Anderson
At the moment the MasterPage doesn't have the model used by the rendered control so I can't pass it to the PartialView. I could re-organise things so my ViewModels inherit from a base ViewModel that holds the master page data I suppose. Not sure where I would put any processing of this data though, the controller RenderPartial sidesteps is the logical place for this. Will have to give it some thought.
Dominic Godin