From what I have understood there is a big difference between the Html.RenderPartial
included in the ASP.NET MVC release and the HTML.RenderAction
in the Microsoft.Web.Mvc.ViewExtensions
included in MVC Futures.
On my application I have many pages composed from many "widgets" (sort of) each having its own specific function.
It seemed to me more reasonable to use the RenderAction
method as each widget would have a dedicated controller responsible for getting different data and rendering a dedicated view (as opposed to having only one controller and a unique view model to pass to RenderPartial
helper to render views).
From the tests I have done having a form that points to a Create action method in a controller like:
<% using (Html.BeginForm("Create", "Message", FormMethod.Post,
new { id = "messageCreateForm" })) {%>
and calling it with
<% Html.RenderPartial("MessageForm",new MessageDTO()); %>
will render correcly a:
<form id="messageCreateForm" method="post" action="/Message/Create">
but with the same equivalent with RenderAction
(so using a MessageForm
action method on the controller to render the view) would not render correcly so:
<% Html.RenderAction<MessageController>(m => m.MessageForm()); %>
will render in:
<form id="messageCreateForm" method="post" action="">
Note that the action is empty.
Is this the correct way to use the RenderAction
helper and is it correct to use it in cases like that?
UPDATE:
Actually renaming the partial view to _MessageForm renders the form correcly.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…