Copied to clipboard

Flag this post as spam?

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


  • Saied 349 posts 674 karma points
    Jun 22, 2016 @ 16:52
    Saied
    0

    Is it possible to pass a custom object into @Umbraco.RenderMacro?

    I created a macro called pSearch, which contains the following code:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using DS.Models
    @model ProductFilterModel
    
    @using (@Html.BeginUmbracoForm("Search", "ProductSearch", new { @Model }, new { @class = "vehicle-filter group", @id = "productFilterForm" }, FormMethod.Get))
    {
    
        <div class="select">
            <select id="YearDropDownList" name="VehicleYear" class="year" data-request-url="@Url.Action("GetVehicleYears","ProductFilter")">
    
            </select>
    
        </div>
    
        <div class="select">
            <select id="MakeDropDownList" name="VehicleMakeId" class="make" disabled data-request-url="@Url.Action("GetVehicleMakes","ProductFilter")"></select>
            @Html.HiddenFor(x => x.VehicleMake)
    
    
    
        </div>
    
        <div class="select">
            <select id="ModelDropDownList" name="VehicleModelId" class="model" disabled data-request-url="@Url.Action("GetVehicleModels","ProductFilter")"></select>
            @Html.HiddenFor(x => x.VehicleModel)
    
        </div>
    
    
        <div class="select">
            <select id="EngineDropDownList" name="VehicleEngineId" class="engine" disabled data-request-url="@Url.Action("GetVehicleEngines","ProductFilter")"></select>
            @Html.HiddenFor(x => x.VehicleEngine)
    
        </div>
    
        <button id="search" type="submit" class="search-button" disabled>SEARCH</button>
        }
    

    Then in my search.cshtml file, I am calling this:

    @Umbraco.RenderMacro("pSearch",new ProductFilterModel())

    But when I got to my search page, it says:

    Error loading Partial View script (file: ~/Views/MacroPartials/psearch.cshtml)

    Apparently, it has something to do with the @inherits keyword is not allowed within @model, so what is the best way to handle this if I need to inherit and pass a custom object model?

  • Saied 349 posts 674 karma points
    Jun 22, 2016 @ 17:06
    Saied
    100

    I ended up removing the @model and doing something like this:

    @using (@Html.BeginUmbracoForm("Search", "ProductSearch", new ProductFilterModel(), new { @class = "vehicle-filter group", @id = "productFilterForm" }, FormMethod.Get)) {....

    This seems to work, but I am not sure if it is the right way

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies