在剃刀视图中使用@ Html.RouteLink将对象传递给控制器​​时,表单对象为null

时间:2018-09-17 20:55:12

标签: asp.net asp.net-mvc

通过单击提交按钮提交表单时,我得到了placeType中的所有值,但是当我单击“ <<<” @Html.RouteLink时,placeType为空。

我需要placeType值才能执行分页。我该怎么做才能使用placeTypeRazorViewController传递到@Html.RouteLink

 @using (Html.BeginForm("PagedPlacesIndex", "Place", FormMethod.Get))
      {
        @Html.AntiForgeryToken()
         <div class="form-horizontal">
       @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group col-lg-3 col-md-3 col-sm-3">
            @Html.LabelFor(model => model.PlaceType.ThemePark, htmlAttributes: new { @class = "control-label col-md-9" })
            <div class="col-md-1">
                <div class="checkbox">
                    @Html.EditorFor(model => model.PlaceType.ThemePark)
                    @Html.ValidationMessageFor(model => model.PlaceType.ThemePark, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group col-lg-3 col-md-3 col-sm-3">
            @Html.LabelFor(model => model.PlaceType.Museum, htmlAttributes: new { @class = "control-label col-md-9" })
            <div class="col-md-1">
                <div class="checkbox">
                    @Html.EditorFor(model => model.PlaceType.Museum)
                    @Html.ValidationMessageFor(model => model.PlaceType.Museum, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group col-lg-3 col-md-3 col-sm-3">
            @Html.LabelFor(model => model.PlaceType.Zoo, htmlAttributes: new { @class = "control-label col-md-9" })
            <div class="col-md-1">
                <div class="checkbox">
                    @Html.EditorFor(model => model.PlaceType.Zoo)
                    @Html.ValidationMessageFor(model => model.PlaceType.Zoo, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group col-lg-3 col-md-3 col-sm-3">
            @Html.LabelFor(model => model.PlaceType.IndoorPlayarea, htmlAttributes: new { @class = "control-label col-md-9" })
            <div class="col-md-1">
                <div class="checkbox">
                    @Html.EditorFor(model => model.PlaceType.IndoorPlayarea)
                    @Html.ValidationMessageFor(model => model.PlaceType.IndoorPlayarea, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group col-lg-3 col-md-3 col-sm-3">
            @Html.LabelFor(model => model.PlaceType.WaterPark, htmlAttributes: new { @class = "control-label col-md-9" })
            <div class="col-md-1">
                <div class="checkbox">
                    @Html.EditorFor(model => model.PlaceType.WaterPark)
                    @Html.ValidationMessageFor(model => model.PlaceType.WaterPark, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group col-lg-3 col-md-3 col-sm-3">
            @Html.LabelFor(model => model.PlaceType.IndoorActivities, htmlAttributes: new { @class = "control-label col-md-9" })
            <div class="col-md-1">
                <div class="checkbox">
                    @Html.EditorFor(model => model.PlaceType.IndoorActivities)
                    @Html.ValidationMessageFor(model => model.PlaceType.IndoorActivities, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group col-lg-3 col-md-3 col-sm-3">
            @Html.LabelFor(model => model.PlaceType.OutdoorActivities, htmlAttributes: new { @class = "control-label col-md-9" })
            <div class="col-md-1">
                <div class="checkbox">
                    @Html.EditorFor(model => model.PlaceType.OutdoorActivities)
                    @Html.ValidationMessageFor(model => model.PlaceType.OutdoorActivities, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group col-lg-3 col-md-3 col-sm-3">
            @Html.LabelFor(model => model.PlaceType.NatureReserve, htmlAttributes: new { @class = "control-label col-md-9" })
            <div class="col-md-1">
                <div class="checkbox">
                    @Html.EditorFor(model => model.PlaceType.NatureReserve)
                    @Html.ValidationMessageFor(model => model.PlaceType.NatureReserve, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group col-lg-3 col-md-3 col-sm-3">
            @Html.LabelFor(model => model.PlaceType.ArtCraftGallaries, htmlAttributes: new { @class = "control-label col-md-9" })
            <div class="col-md-1">
                <div class="checkbox">
                    @Html.EditorFor(model => model.PlaceType.ArtCraftGallaries)
                    @Html.ValidationMessageFor(model => model.PlaceType.ArtCraftGallaries, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group col-lg-3 col-md-3 col-sm-3">
            @Html.LabelFor(model => model.PlaceType.HistoryHeritage, htmlAttributes: new { @class = "control-label col-md-9" })
            <div class="col-md-1">
                <div class="checkbox">
                    @Html.EditorFor(model => model.PlaceType.HistoryHeritage)
                    @Html.ValidationMessageFor(model => model.PlaceType.HistoryHeritage, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

        <div class="form-group col-lg-3 col-md-3 col-sm-3">
            @Html.LabelFor(model => model.PlaceType.SportLeisure, htmlAttributes: new { @class = "control-label col-md-9" })
            <div class="col-md-1">
                <div class="checkbox">
                    @Html.EditorFor(model => model.PlaceType.SportLeisure)
                    @Html.ValidationMessageFor(model => model.PlaceType.SportLeisure, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

      <div class="form-group col-lg-3 col-md-3 col-sm-3">
        @Html.LabelFor(model => model.PlaceType.Beach, htmlAttributes: new { @class = "control-label col-md-9" })
        <div class="col-md-1">
          <div class="checkbox">
            @Html.EditorFor(model => model.PlaceType.Beach)
            @Html.ValidationMessageFor(model => model.PlaceType.Beach, "", new { @class = "text-danger" })
          </div>
        </div>
      </div>
      <div class="form-group col-lg-3 col-md-3 col-sm-3">
        @Html.Label("sortOrder", htmlAttributes: new { @class = "control-label col-md-9" })
        <div class="col-md-1">
          <div class="checkbox">
            @Html.DropDownList("sortOrder", new List<SelectListItem>
            {
              new SelectListItem{ Text="Name Descending", Value = "name_desc" },
              new SelectListItem{ Text="Name Ascending", Value = "" },
              new SelectListItem{ Text="Date Descending", Value = "date_desc" },
              new SelectListItem{ Text="Date Ascending", Value = "Date" }
            },null,new {@class= "dropdown - menu" })
            @Html.ValidationMessageFor(model => model.PlaceType.Beach, "", new { @class = "text-danger" })
          </div>
        </div>
      </div>

      <input type="hidden" name="selectionChecked" value="true" />
        <div class="form-group col-lg-3 col-md-3 col-sm-3">
            <div class="col-md-offset-8  col-md-3">
                <input type="submit" value="Update Search" class="btn btn-xs btn-success" />
            </div>
        </div>
    </div>
@if(Model.HasPreviousPage)
{
@Html.RouteLink("<<<", "Places", new
{
  page = (Model.PageIndex - 1), placeType = Model.PlaceType
})
}
@if(Model.HasNextPage)
{
@Html.RouteLink(">>>", "Places", new {page = (Model.PageIndex + 1), placeType = Model.PlaceType})
}

就地控制器:-

public ActionResult PagedPlacesIndex(string sortOrder, int? page, bool? selectionChecked, PlaceType placeType)
    {

      IEnumerable<Place> places = _db.Places;
      IEnumerable<Place> sortedPlaces = SortPlaces(places, sortOrder);
      IEnumerable<Place> filteredPlaces = null;
      if (placeType != null)
      {
        bool placeTypeCheck = placeSetorNotCheck(placeType);
        if (placeTypeCheck)
        {
          filteredPlaces = FilteredPlaces(sortedPlaces, placeType);
        }
        else
        {
          filteredPlaces = sortedPlaces;

        }
      }
      else { filteredPlaces = sortedPlaces; }

      page = page ?? 0;
      const int pageSize = 5;
      var pagedPlaces = new PaginatedList<Place>(filteredPlaces,placeType, page ?? 0, pageSize);
      return View(pagedPlaces);
    }

0 个答案:

没有答案