1

I have a paged list using unobtrusive ajax that looks like this.

@Html.PagedListPager(Model, page => Url.Action("Images", "Admin", new { imageLibrary = image.ImageLibrary, page }),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions()
{ InsertionMode = InsertionMode.Replace, UpdateTargetId = "imagesContainer" }))

My controller looks like this:

public ActionResult Images(ImageModels image, int? page, string imageLibrary)
{
   // do stuff here
}

I was trying to pass a model to my controller, so instead of imageLibrary = image.ImageLibrary, I should have only needed to pass image = imageModel, but when I pass the model itself, the controller gets a null value (yes the model name was spelled correctly). When I try to get a property of the model and pass it to the controller (that's the imageLibrary = image.ImageLibrary) the controller receives both the model and the imageLibrary string value! This works fine for the end result, I just don't understand why it works, and I shouldn't have to pass the string value imageLibrary to my controller - especially if I'm not really using it.

Any insight on this would be appreciated.

Nkosi
  • 235,767
  • 35
  • 427
  • 472
mbuchok
  • 391
  • 6
  • 18
  • 1
    To pass the model, it would be `new { Model }` (not `new { image = Model }`) but it would only work if the Model contains simple properties. But what would be the point of passing back the same unchanged model to the server which just sent it? –  Apr 19 '16 at 11:17
  • post your ImageModels class code here. – Pawan Lakhara Apr 19 '16 at 12:24
  • @StephenMuecke It's actually more to do with my stored procedure. There are cases where I filter by more than just one property so rather than passing individual properties my stored procedure looks for whether they are null else look at the next property and so on... perhaps there's a better way to do what I'm doing... Anyway, you answered me correctly - I needed to pass just 'Model' not 'image = Model'. Thanks for that, I appreciate it :-) – mbuchok Apr 19 '16 at 19:18
  • @MichaelBuchok, If the model your passing back contains simple properties (`string`, `int` etc) that your using to store values for filtering, sorting etc, then what your doing is fine. But if the model contains any properties which are complex objects or collections, then those properties will not be bound in the controller. –  Apr 20 '16 at 01:29
  • @StephenMuecke Good to know, thanks Stephen :-) – mbuchok Apr 20 '16 at 11:03

0 Answers0