Great job on this package, I've got my MVC partials rendering correctly within my Umbraco pages. The only thing is, in my view I'm using standard MVC forms to post to actions within my controller, but the action URL is not being rendered, and hence the controller does not pickup the posted data.
To clarify, I have some code like this in my view (my view is called "CourseList.cshtml"):
... the end result being, my controller action is never called. I suppose this makes sense as the MVC routes are not registered anywhere (like they are in the Global.asax in a standard MVC application) so by trying to resolve "SearchCourses" action in "Course" controller, it fails and hence can't produce a URL to post the form to.
So what am I missing to make this work? I assume it is possible to have a form in an MVC view that posts to a different action?
Using forms in partial views
Hi,
Great job on this package, I've got my MVC partials rendering correctly within my Umbraco pages. The only thing is, in my view I'm using standard MVC forms to post to actions within my controller, but the action URL is not being rendered, and hence the controller does not pickup the posted data.
To clarify, I have some code like this in my view (my view is called "CourseList.cshtml"):
@inherits Devotit.Umbraco.MvcBridge.MvcBridgeView<Lifetime.Cms.Mvc.ViewModels.CourseListViewModel>
@using (Html.BeginForm("SearchCourses", "Course"))
{
@Html.TextBoxFor(x => x.Name)
<input type="submit" value="Submit" />
}
I am adding this view to my umbraco page using the following call to the macro:
<umbraco:Macro ID="Macro1" Alias="MvcRenderAction" runat="server" Controller="Course" Action="CourseList" />
And this in my controller:
public PartialViewResult CourseList()
{
return PartialView(new CourseListViewModel());
}
public PartialViewResult SearchCourses(CourseListRequest model){
return PartialView("Success");
}
... but the output HTML of the form does not have any URL for the action:
<form action="" method="post">
<input id="Name" name="Name" type="text" value="" />
<input type="submit" value="Submit" />
</form>
... the end result being, my controller action is never called. I suppose this makes sense as the MVC routes are not registered anywhere (like they are in the Global.asax in a standard MVC application) so by trying to resolve "SearchCourses" action in "Course" controller, it fails and hence can't produce a URL to post the form to.
So what am I missing to make this work? I assume it is possible to have a form in an MVC view that posts to a different action?
Hi,
never tried that. The MVC routes are indeed missing as you said. Url routing is missing in MvcBridge (Inbound and Outbound)
You might try to hard code the action url in your form.
Not optimal but might work.
Cheers,
Richard
is working on a reply...