.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 = "" });
items.Add(new SelectListItem { Text = "香蕉", Selected = true });
items.Add(new SelectListItem { Text = "柚子", Value = "" }); 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;}
}
}