导航

MVC表单

Posted on 2016-04-12 21:56  颍川小哥  阅读(208)  评论(1编辑  收藏  举报
.cs
namespace SendToMvcHello.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public string SendHello(HelloPerson helloPerson)
        {
            return helloPerson.name.ToString() + ",你好!";
        }
        public ActionResult Hello()
        {
            List<SelectListItem> items = new List<SelectListItem>();
            items.Add(new SelectListItem { Text = "苹果", Value = "29" });
            items.Add(new SelectListItem { Text = "香蕉", Selected = true });
            items.Add(new SelectListItem { Text = "柚子", Value = "29" });

            this.ViewData["list"] = items;
            return View();
        }
    }
}


.Hello.cshtml

<body>
    <div>
        @using (Html.BeginForm("SendHello", "Home"))
        {
            // @Html.AntiForgeryToken()
            // @Html.ValidationSummary(true)
            @:请输入你的姓名:
            @Html.TextBoxFor(x => x.name);
            <input type="submit" value="Hello" />;
            @Html.DropDownList("list");
        }

    </div>
</body>

.cs
namespace SendToMvcHello.Models
{
    public class HelloPerson
    {
        public String name {get; set;}
    }
}