Html.Partial在ActionResult和PagedList上获取输入名称?

时间:2017-10-16 11:33:50

标签: asp.net-mvc pagedlist

我有port我使用ActionResult来展示一些产品,在PagedList我创建了一个搜索按价格查找所有产品或产品。问题是我创建它是部分的,现在我尝试将其渲染为ActionResult,它运行良好,但我无法从@HTML.Partial("_SearchProducts")获取输入名称_SearchProductsActionResult置于@Url.Action以保持搜索值。

我怎么能这样做?

SearchProducts(部分)

<div class="panel panel-red">
    <div class="panel-body">

        @using (Html.BeginForm("showAnuncioPropIM", "Anuncio", FormMethod.Post, new { Class = "form-inline", role = "form" }))
        {
            @Html.AntiForgeryToken()
            @Html.ValidationSummary(true)

            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><i class="glyphicon glyphicon-usd"></i></span>
                    <input type="text" class="form-control money2" placeholder="Investimento mínimo USD$" id="min" name="min" size="25" style="z-index:0 !important;" />
                </div>
            </div>

            <div class="form-group">
                <div class="input-group">
                    <span class="input-group-addon"><i class="glyphicon glyphicon-usd"></i></span>
                    <input type="text" class="form-control money2" placeholder="Investimento máximo USD$" id="max" name="max" size="25" style="z-index:0 !important;" />
                </div>
            </div>

            <button type="submit" class="btn btn-default glyphicon glyphicon-search"></button>
        }

    </div><!--/panel body-->
</div><!--/panel-->

产品(ActionResult)

@model PagedList.IPagedList<AddAnuncioIMModel>
@using PagedList.Mvc

@{
    ViewBag.Title = "showAnuncioPropIM";
    Layout = "~/Views/Shared/_LayoutConta.cshtml";
}



@Html.Partial("_SearchProducts")

<!--apresentacao-->
<div class="panel">    

    @if (Model.Count == 0){
        <h2 class="text-center">Nenhuma opção de investimento encontrada</h2>
    }
    else{
        <div class="row">
          @foreach (AddAnuncioIMModel m in Model){
              <div class="col-md-3">
                  <div class="panel panel-red">
                      <div class="panel-heading bg-red"><strong>Propriedade: #@Html.DisplayFor(i => m.id)</strong></div>
                      <div class="panel-body">
                          <img class="img-responsive" src="~/Imagens/Anuncios/@Url.Content(m.imgExibicao)" /> 
                          <h5 class="text-center">Valor de Mercado</h5>
                          <h5 class="text-center" style="color:orange;font-weight:bold;">$@Html.DisplayFor(i => m.valorMercado)</h5>                         
                          <h5 class="text-center">Investimento</h5>
                          <h4 class="text-center" style="color:green;font-weight:bold;">$@Html.DisplayFor(i => m.valorInvestimento)</h4>
                          <h5 class="text-center">Previsão de Lucro</h5>
                          <h5 class="text-center" style="color:blue;font-weight:bold;">$@Html.DisplayFor(i => m.valorPrevLucro)</h5>
                          @*<a href="#" class="btn btn-success btn-block">Comprar</a>*@
                          @Html.ActionLink("Comprar", "detailAnuncioIM", "Anuncio", new { id = EncodingParams.encode(Convert.ToString(@m.id)) }, new { Class = "btn btn-success btn-block" })
                      </div>
                  </div>
              </div>
          }
        </div>
        <p>Página @Model.PageNumber de @Model.PageCount</p>
        @Html.PagedListPager(Model, page => Url.Action("showAnuncioPropIM", new { pagina = page, min = min, max = max }))
    }
</div>
<!--/apresentacao-->

控制器

public ActionResult showAnuncioPropIM(int? pagina, decimal? min, decimal? max){
            int tamanhoPagina = 20;
            int numeroPagina = pagina ?? 1;

            IList<AnuncioIM> _lista = new List<AnuncioIM>();
            IList<AddAnuncioIMModel> _listaModel = new List<AddAnuncioIMModel>();

            try{
                decimal valMin = min ?? 0;
                decimal valMax = max ?? 0;
                if (valMax > 0){
                    _lista = new AnuncioIMDAO().findAllAnunciosByValorMinMax(valMin, valMax);
                }else{
                    _lista = new AnuncioIMDAO().findAllByValor();
                }

            }catch (Exception e){
                Debug.WriteLine("AnuncioController showAnuncioPropIM: " + e.InnerException.Message);
            }
            foreach (AnuncioIM x in _lista){
                AddAnuncioIMModel model = new AddAnuncioIMModel();
                model.id = x.id;
                model.valorMercado = x.valorMercado;
                model.valorInvestimento = x.valorInvestimento;
                model.valorPrevLucro = x.valorPrevLucro;
                model.banheiros = x.pesquisa.banheiros;
                model.quartos = x.pesquisa.quartos;
                model.m2 = x.pesquisa.m2;
                model.imgExibicao = x.imagens[0].nome;
                _listaModel.Add(model);
            }

            return View(_listaModel.ToPagedList(numeroPagina, tamanhoPagina));
        }

0 个答案:

没有答案