Html.BeginForm()没有向控制器返回值

时间:2017-01-17 22:06:22

标签: asp.net-mvc

Html.BeginForm()没有从@Html.TextBoxFor(p => p.Number)返回值;对于控制器,在书中是完全一样的,它在哪里工作,有什么不对?

@model FrizzBuzz1.Models.dane
....
<body>
    <div class="panel-body"> 
        @using (Html.BeginForm())
        {
            @Html.TextBoxFor(p => p.Number);
        }
        <input class="btn-success" type="submit" value="Wyslij" />
    </div>
</body>

控制器

[HttpGet]
public ViewResult Index()
{
    return View();
}
[HttpPost]
public ViewResult Index(dane Dane)
 {

    if (Dane.Number % 3 == 0 && Dane.Number % 5 != 0)
    {
        Dane.napis = "Fizz";
    }
    else if(Dane.Number % 5 == 0 && Dane.Number % 3 != 0)
    {
        Dane.napis = "Buzz";
    }
    else if (Dane.Number % 5 == 0 && Dane.Number % 3 == 0)
    {
        Dane.napis = "FizzBuzz";
    }
    else 
    {
        Dane.napis = "Nic";
    }
   return View("Index", Dane);
}

模型

public class dane
{
    public int Number;
    public string napis;
} 

0 个答案:

没有答案