views:

171

answers:

1

I got a page that lists all my articles (Articles/List.aspx).

I also got a control that create article (Article/Create.ascx).

I will like that my List.aspx page that's render the Create.ascx to be able to create article.

I know that in MVC, the preferred approach is one page by action. But in this case I need to do that. It's a design issue and how the client want the Web site to work.

So for now, I got the following code in List.aspx :

<% Html.RenderPartial("Create", new Domain.Models.Article()); %>

That render correctly. But when I hit the create button, it's doesn't go in the Create[post] method of my ArticleController.

Any idea why and how I could resolve that issue ?

+1  A: 

If you have problems with the button, it's not going to have anything to do with how you're rendering the user control. We need to see the form markup that the button is inside, that will show what the problem is most likely.

But just for reference, you're probably looking to do something like this:

<% using (Html.BeginForm("Create", 
    ViewContext.RouteData.Values["Controller"].ToString())) { %> 

    your control markup here

<% } %>
Joseph
The problem is not with the button, because if I put all my code in a standard Create.aspx page (instead of a control), it's work. But, your right, your code is what I was looking for. I appreciate your quick and good answer!
Melursus
@Melursus The problem is not the button most likely, it's the form the button is in. In a control, you need to know which controller to use, which may or may not be what you're expecting it to be. That's why I included the ViewContext.RouteData.Values["Controller"]. That refers to the controller that is building the user control from inside the page. That way you know you're getting the controller that it was called from.
Joseph
Thank for the clarification! That's help me to get a better understanding!
Melursus