你的模型是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace radiotest.Models
{
public class SomeOrder
{
public string TypeDrink { get; set; }
}
}
你的观点是 index.cshtml
@model radiotest.Models.SomeOrder
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm())
{
<fieldset>
<div class="editor-field">
@Html.RadioButtonFor(m => m.TypeDrink, "1") Tea
@Html.RadioButtonFor(m => m.TypeDrink, "2") Coffee
@Html.RadioButtonFor(m => m.TypeDrink, "3") Juice
</div>
<div> <input type="submit" value="Submit" /></div>
</fieldset>
}
您在 HTTP Get 和 Post 中的控制器是:
using radiotest.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace radiotest.Controllers
{
public class TestController : Controller
{
public ActionResu`enter code here`lt Index()
{
SomeOrder se = new SomeOrder{ TypeDrink="3" };
return View(se);
}
[HttpPost]
public ActionResult Index(SomeOrder model)
{
//model.TypeDrink gives you selected radio button in HTTP POST
SomeOrder se = new SomeOrder {TypeDrink = model.TypeDrink };
return View(se);
}
}
}