I have an MVC action on my abstract BaseControlller like this (and this action is common across all inheriting controllers):
//
// GET: /controller/RenderForm/{formType}
[Authorize(Roles = "Administrators")]
public ActionResult RenderForm(FormType formType, BaseContentObject contentObject)
{
string constructPartialViewName = RouteData.Values["controller"] + "-" + formType + "Form";
return PartialView(constructPartialViewName, contentObject);
}
with this route:
routes.MapRoute(
"ContentObjectsFormRendering",
RouteType.Regular,
"{controller}/RenderForm/{formType}",
new {controller = "", action = "RenderForm", formType = ""}, null
);
The problem comes in when I make a browser request like:
~/Page/RenderForm/Create
This is a request to render a Create form. This is done from the browser - for instance, typing in the URL. There is no BaseContentObject instance here (please note that this can never be provided thru browser for Create as it is always pulled out of datastore in case of editing) and I think this is what is bothering him.
(The exception is: Cannot create an abstract class.)
But when performing RenderAction like this:
<%
Html.RenderAction("RenderForm", ViewData.Model.ContentType.ToString(), new {formType = FormType.Edit, contentObject = ViewData.Model}); %>
it renders the Edit form with details from BaseContentObject instance (provided thru ViewData) just fine.
If I remove the BaseContentObject contentObject parameter from the action then rendering Create works fine but then I cannot provide the content object param in the second case for Edit.
How can I solve this?