.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;} } }
时间: 2024-10-24 00:50:49