MVC 5单击按钮获取值

时间:2018-08-21 13:25:41

标签: drop-down-menu asp.net-mvc-5 textbox buttonclick

我是Web编程的新手,我想做的是将值从下拉菜单和文本框传递到其他文本框。我想在单击按钮时执行此操作。

我的视图如下:

    @{
        ViewBag.Title = "Sort";

        List<SelectListItem> liSort = new List<SelectListItem>();
        liSort.Add(new SelectListItem() { Text = "ASC", Value = "1" });
        liSort.Add(new SelectListItem() { Text = "DESC", Value = "2" });

        List<SelectListItem> liNumber = new List<SelectListItem>();
        liNumber .Add(new SelectListItem() { Text = "10", Value = "10" });
        liNumber .Add(new SelectListItem() { Text = "20", Value = "20" });
        liNumber .Add(new SelectListItem() { Text = "50", Value = "50" });
        liNumber .Add(new SelectListItem() { Text = "100", Value = "100" });
    }

    <table class="table">
        <tr>
            <th>Sort order</th>
            <th>Number of records per page</th>
            <th>Search parameter</th>
        </tr>

<tr>

> This are my two DropDownLists, textbox and button

            <td>@Html.DropDownList("Sort", liSort, "--Select--", new { @style = "width:200px; height:30px" })</td>
            <td>@Html.DropDownList("Number", liNumber, "--Select--", new { @style = "width:200px; height:30px" })</td>
            <td>@Html.TextBox("Search", null, new { @style = "width:200px; height:30px" })</td>
            <td>@using (Html.BeginForm("GetValues", "MYController", FormMethod.Post))
                {
                    <input type="submit" value="GO!" />
                }
             </td>
        </tr>
        <tr>

> This are the text boxes where I would like to have my selected values

            <td>Sort order value: @Html.TextBox("SortValue", null, new { @style = "width:200px; height:30px" })</td>
            <td>Number of records per page value: @Html.TextBox("NumberValue", null, new { @style = "width:200px; height:30px" })</td>
            <td>Search parameter value: @Html.TextBox("SearchValue", null, new { @style = "width:200px; height:30px" })</td>
        </tr>
    </table>

我想知道的是,我需要将值传递给MYController并在那里执行代码(在我的GetValues方法中),还是可以在View中编写代码?

那当然应该是什么代码(如何获取值)?

感谢任何可以帮助我的人。

Grega

0 个答案:

没有答案