I've encountered what seems to be a strange inconsistency in the values of properties in my model.

I have the following controller action...

<Route("news/edit")>
<HttpGet>
Function EditIndex(Optional filter As Models.NewsFilter = Nothing) As ActionResult
   filter.Start = 0
   filter.Count = 100

   Return View("EditIndex", filter)
End Function

Most of the properties in the model come from the querystring, but my controller explicitly setting "Start" and "Count", and then passing the model to the view.

My view is declared like so...

@inherits System.Web.Mvc.WebViewPage(Of Models.NewsFilter)

The odd thing is that if I simply display the models properties within the view like...

Start=@Model.Start
Count=@Model.Count

They display the values as defined in my controller. However when I use the following...

@Html.EditorFor(Function(m) m.Start, New With {.class = "form-control"})
@Html.EditorFor(Function(m) m.Count, New With {.class = "form-control"})

The values displayed are the original values from the QueryString. It's ignoring the values that I've set in my controller.

I don't understand why this happens. Is it trying to be clever and automatically checking the QueryString parameters because it's within a form?

Related posts

Recent Viewed