The problem isn't that null
isn't returned by the POST, but that null
IS returned by the POST.
Since your action has a default value of 2. When the action is receiving null
the it's initializing the variable with the default value, in that case 2
public ActionResult Index(int? All = 2)
What you want to do it to be able to differentiate between "All items" and the default behavior of the app. It that case, the default behavior is to show only flats
You can achieve that goal by using building the "All items" inside of your controller.
public ActionResult Index(int? All = 2)
{
var propertyTypesSelectList = new SelectList(property_types.Select(x => new {v = x.Value, t = x.Key.ToLower()}), "v", "t", All).ToList();
propertyTypesSelectList.Insert(0, new SelectListItem() { Value = "0", Text = "All items"});
ViewData["All"] = propertyTypesSelectList;
return View();
}
And changing your View to this
@Html.DropDownList("All")