Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • daveb.84 21 posts 46 karma points
    Oct 11, 2011 @ 14:13
    daveb.84
    0

    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?

  • Richard Boelen 61 posts 153 karma points
    Oct 12, 2011 @ 08:44
    Richard Boelen
    0

    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

     

Please Sign in or register to post replies

Write your reply to:

Draft