如何从textboxFor获得用户输入

时间:2018-12-27 13:46:47

标签: c# asp.net-mvc

我正在尝试从TextBoxFor获取输入,因此,如果用户输入整数,它将以升序排序。如何从textBoxFor中检索用户输入并将其添加到升序函数中,结果应显示用户输入,以及他是否在ASC或DESC中选择了整数顺序。 我尝试了很多方法,但是仍然行不通。任何帮助,将不胜感激。谢谢

@model TechnicalTest.Models.Input



@{
    ViewBag.Title = "Home Page";


}



<div class="jumbotron">

    <h1 class="display-3">Enter Values!</h1>

    @*@Html.TextBox("Input", Model.InputNumber)*@




    @*<input type="submit" value="Add" class="btn btn-secondary" />*@<br />

    @using (Html.BeginForm("Input", "Home", FormMethod.Get))
    {
        @Html.TextBoxFor(model => model.InputNumber)


    }

    @using (Html.BeginForm("AscendingOrder", "Home", FormMethod.Post))
    {
        <input type="submit" value="Ascending number order" class="btn btn-secondary"/>

    }


        <input type="submit" value="Descending number order" class="btn btn-secondary" />


    </div>



  namespace TechnicalTest.Models
{
public class AscendingOrder : Input
{
    public List<int> ascendingOrderFunction(List<int> myNumbers)
    {

        myNumbers.Sort();

    return myNumbers;
    }


    public List<int> descendingOrderFuncion(List<int> myNumbers)
    {
        myNumbers.Sort();
        return myNumbers;
    }
}
}



 namespace TechnicalTest.Controllers
{
    public class HomeController : Controller
    {
        private readonly AscendingOrder ascendingOrder = new AscendingOrder();
    private List<int> myNumbers = new List<int>();
    public Input uInput = new Input();


    public ActionResult Index()
    { 

        return View();
    }



    public ActionResult AscendingOrder (int myNumber)
    {

        uInput.InputNumber = myNumber;
        myNumbers.Add(myNumber);
        return View(ascendingOrder.ascendingOrderFunction(myNumbers));
    }


    public ActionResult DescendingOrder(int myNumber)
    {
        uInput.InputNumber = myNumber;
        myNumbers.Add(myNumber);
        return View(ascendingOrder.ascendingOrderFunction(myNumbers));
    }


}
}

0 个答案:

没有答案