mvc4中的多个参数

时间:2016-08-19 07:26:16

标签: asp.net-mvc asp.net-mvc-4

我正在学习MVC并且坚持这一点。我试图为名称,类别,类型,最小值,最大值创建过滤器,但是当重定向到另一个视图时,它只显示三个参数但没有其他值。

Controller(DetailController)

public ActionResult FilteredResult(string searchedLocation, string Type, string PCName, string MinValue, string MaxValue)
{
    var A = searchedLocation;
    var B = Type;
    var C = PCName;
    var D = MinValue;
    var E = MaxValue;
    return View();
}

查看

@using (Html.BeginForm("FilteredResult", "Detail", FormMethod.Get))
{
    <form>
        <h4 style="color: #ed145b;">Find the right property for you</h4>
        <ul class="form-style-1">
            <li>
                @Html.TextBox("Location", ViewBag.Location as string , new { @class = "field-long" })
            </li>
            <li>
                @Html.DropDownList("Type", (SelectList)ViewBag.TypeList, "Select" , new { @class = "field-select" })
            </li>
            <li>
                @Html.DropDownList("Category", (SelectList)ViewBag.CategoryList, "Select" ,new { @class = "field-select" })
            </li>
            <li>
                <label for="amount">Price range:</label>
                <input type="text" id="amount" class="field-long" readonly style="border:0; color:#ee2265; font-weight:bold;">
            </li>
            <li class="clearfix"> @Html.TextBox("MinValue", ViewBag.MinValue as string, new { @class = "Minprice field-long", disabled = "true" })
                @Html.TextBox("MaxValue", ViewBag.MaxValue as string, new { @class = "Maxprice field-long", disabled = "true" })
            </li>
            <li>
                <div id="slider-range"></div>
            </li>
            <li>
                <input type="submit" value="Search" class="btn-primary" />
            </li>
        </ul>
    </form>
}

enter image description here

点击搜索后,它会显示如下。仅显示来自下拉列表的数据,并且其他参数(如最小值和最大值)未显示在URL中。位置正在显示

enter image description here

任何人都可以帮助我如何在控制器的必填字段中成功获取数据吗?

2 个答案:

答案 0 :(得分:2)

这是因为您的MinValue和MaxValue文本框具有disabled="true"属性。禁用的输入不会被提交

@Html.TextBox("MinValue", ViewBag.MinValue as string, new { @class = "Minprice field-long", disabled = "true" })
@Html.TextBox("MaxValue", ViewBag.MaxValue as string, new { @class = "Maxprice field-long", disabled = "true" })

您应该删除disabled属性

@Html.TextBox("MinValue", ViewBag.MinValue as string, new { @class = "Minprice field-long" })
@Html.TextBox("MaxValue", ViewBag.MaxValue as string, new { @class = "Maxprice field-long" })

如果您想使这些文本框不可编辑,请使用readonly属性

@Html.TextBox("MinValue", ViewBag.MinValue as string, new { @class = "Minprice field-long", @readonly = "readonly" })
@Html.TextBox("MaxValue", ViewBag.MaxValue as string, new { @class = "Maxprice field-long", @readonly = "readonly" })

答案 1 :(得分:0)

因为您使用的是disabled属性,这意味着它从数据库中获取数据但不会在View上显示,因此要么禁用=“false”,要么删除此属性。