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
    Sep 11, 2015 @ 15:43

    Passing model to BeginUmbracoForm Action is null?

    I have a Partial View that has the contains this snippet of BeginUmbracoForm:

    @model ProductFilterModel
    @using (@Html.BeginForm("Search", "ProductSearch", new {model = new ProductFilterModel(),@Model.YearId, @Model.MakeId, @Model.ModelId, Engine = @Model.EngineId }, FormMethod.Get, new { @class = "vehicle-filter group", @id = "productFilterForm" }))

    When the Search Action is called, the model object is null, but the other values are fine. I was trying to just pass model = new ProductFilter(MakeId = @Model.MakeId....), but it is null when it hits the Action. Here is the Action method:

    //model is null, but the other string values are not
    public ActionResult Search(ProductFilterModel model, string yearId, string makeId, string modelId, string engineId)
                var db = new Database("productsDb");
                var productSearchResultsModel = new ProductSearchResultsModel
                    ProductFilterModel = new ProductFilterModel{ YearId = yearId, MakeId = makeId, ModelId = modelId, EngineId = engineId},
                    Products = db.Fetch<ProductViewModel>(@"SELECT DISTINCT(p.ProductID) As ProductId, Type, Name, PartNumber, ShortDescription
                                                            FROM Products p
                                                            INNER JOIN productlink pl on pl.ProductID = p.ProductID
                                                            INNER JOIN vehicles v on v.VehicleID = pl.VehicleID
                                                            WHERE Brand = 'SCT'
                                                            AND v.Make = @MakeId
                                                            AND v.Model = @ModelId
                                                            AND v.Engine = @EngineId
                                                            AND v.Year = @YearId", new { YearId = yearId,MakeId = makeId,ModelId = modelId,EngineId = engineId  })
                return View("~/Views/Filter.cshtml",productSearchResultsModel);
  • Benas Brazdziunas 34 posts 155 karma points c-trib
    Oct 01, 2015 @ 14:10
    Benas Brazdziunas

    For a start your snippet uses BeginForm instead of BeginUmbracoForm

Please Sign in or register to post replies

Write your reply to: