0

我的观点如下。我有两个提交按钮;一为find new car一为find used car。如何获取控制器中选定下拉列表的值?

以及如何找出用户按下了 2 个按钮中的哪一个?

@{
        ViewBag.Title = "Home Page";
    }
    @using (Html.BeginForm("Home", "home"))
    {

        <table>
            <tr>
                <td>
                    <h2>
                        Find New car</h2>
                    <table>
                        <tr>
                            <td>
                                <select id="ddlBrand" name="ddlbrand" style="width: 200px;">
                                    <option value="0">---Select Brand---</option>
                                    <option value="1">---b1---</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <select id="ddlModel" name="ddlModel" style="width: 200px;">
                                    <option value="0">---Select Model---</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <select id="ddlFuelType" name="ddlFuelType" style="width: 200px;">
                                    <option value="0">---Select Fuel Type---</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <select id="ddlBudget" name="ddlBudget" style="width: 200px;">
                                    <option value="0">---Select Your Budget---</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="button" name="FindNewCar" value="GO"  />
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    <h2>
                        Find used car</h2>
                    <table>
                        <tr>
                            <td>
                                <table>
                                    <tr>
                                        <td>
                                            <select id="ddlBrand1" name="ddlbrand" style="width: 200px;">
                                                <option value="0">---Select Brand---</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <select id="ddlModel2" name="ddlModel" style="width: 200px;">
                                                <option value="0">---Select Model---</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <select id="ddlFuelType2" name="ddlFuelType" style="width: 200px;">
                                                <option value="0">---Select Fuel Type---</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <select id="ddlCity" name="ddlCity" style="width: 200px;">
                                                <option value="0">---Select City---</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input type="button" name="FindNewCar" value="GO" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td>
                                <table>
                                    <tr>
                                        <td>
                                            <h4>
                                                Sell Car</h4>
                                            <br />
                                            Sell your car faster, at right price ...<a href="#"> Sell Car»</a>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    aaaaaaaaaaa
                </td>
            </tr>
        </table>

    }
4

1 回答 1

-1

您应该在控制器内部设置两个操作方法并使用 Html.ActionLink 方法来帮助创建表单。

例子:

public ActionResult FindNewCar(string ddlbrand, string ddlModel, string ddlFuelType, string ddlBudget)
{
     // Do something here.
}

public ActionResult FindUsedCar(string ddlbrand2, string ddlModel2, string ddlFuelType2, ddlCity)
{
     // Do something here.
}

看法

@using (Html.BeginForm("Home", "home"))
{
     @Html.ActionLink(...)
}

编辑

请参阅上面的更改

于 2012-10-06T14:17:55.773 回答