我正在阅读MVC教程,其中展示了如何根据Database表中的条目创建单选按钮。作为MVC和Linq的新手,我对以下代码中m=>m.SelectedCompany
实际做了什么感到困惑?
表格
+-----------+-------------+------------+
| CompnayId | CompanyName | IsSelected |
+-----------+-------------+------------+
| 1 | Accenture | 0 |
| 2 | CMS | 1 |
| 3 | Microsoft | 0 |
+-----------+-------------+------------+
MODEL:
public class CompanyC
{
public string SelectedCompany { get; set; }
public List<Company> Companies
{
get
{
testDbContext db = new testDbContext();
return db.Companies1.ToList();
}
}
}
控制器:
public class CompanyController : Controller
{
//
// GET: /Company/
public ActionResult Index()
{
CompanyC company = new CompanyC();
return View(company);
}
}
查看:
@model MvcKudvenkat1.Models.CompanyC
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm())
{
foreach (var company in Model.Companies)
{
@Html.RadioButtonFor(m=>m.SelectedCompany,company.CompnayId) @company.CompanyName
}
<br />
}
我尝试了解MSDN以了解RadioButtonFor的语法,但我不知道RadioButtonFor<TModel, TProperty> Method (HtmlHelper<TModel>, Expression<Func<TModel, TProperty>>, Object)
这意味着什么?
基本上我的问题是......
RadioButtonFor接受的不同参数是什么,m=>m.SelectedCompany
在上面的代码中做了什么?